本文整理匯總了Java中com.google.appengine.api.memcache.MemcacheService.get方法的典型用法代碼示例。如果您正苦於以下問題:Java MemcacheService.get方法的具體用法?Java MemcacheService.get怎麽用?Java MemcacheService.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.appengine.api.memcache.MemcacheService
的用法示例。
在下文中一共展示了MemcacheService.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: detect
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
public Language detect(String str){
String key = str;
String code = "";
// Using the synchronous cache
MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
//syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
code = (String) syncCache.get(key); // read from cache
if (code == null) {
System.out.println("Cache miss");
code = detectFromAPI(key);
syncCache.put(key, code);
} else{
System.out.println("Cache hit");
}
String label = getLangaugeLabel(code);
Language lang = new Language(code, label);
return lang;
}
示例2: doGet
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
String path = req.getRequestURI();
if (path.startsWith("/favicon.ico")) {
return; // ignore the request for favicon.ico
}
MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
byte[] whoKey = "who".getBytes();
byte[] countKey = "count".getBytes();
byte[] who = (byte[]) syncCache.get(whoKey);
String whoString = who == null ? "nobody" : new String(who);
resp.getWriter().print("Previously incremented by " + whoString + "\n");
syncCache.put(whoKey, "Java".getBytes());
Long count = syncCache.increment(countKey, 1L, 0L);
resp.getWriter().print("Count incremented by Java = " + count + "\n");
}
示例3: countPackages
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
/**
* @return the number of packages
*/
public static int countPackages() {
final String key =
NWUtils.class.getName() + "[email protected]" +
NWUtils.getDataVersion();
MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
syncCache.setErrorHandler(ErrorHandlers
.getConsistentLogAndContinue(Level.INFO));
Integer value = (Integer) syncCache.get(key); // read from cache
if (value == null) {
ShardedCounter sc =
ShardedCounter.getOrCreateCounter("NumberOfPackages", 2);
value = sc.getCount();
if (sc.getCount() == 0) {
Objectify ofy = DefaultServlet.getObjectify();
sc.increment(ofy.query(Package.class).count());
value = sc.getCount();
}
syncCache.put(key, value); // populate cache
}
return value;
}
示例4: doGet
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
final String uuid = request.getParameter(UpdatePositionServletImpl.PARAMETER_UUID);
if (uuid == null || uuid.trim().equals("")) {
response.sendError(HttpStatus.SC_BAD_REQUEST, "?uuid= mandatory");
}
final MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
final Object inMemory = syncCache.get(uuid);
if (inMemory == null) {
response.sendError(HttpStatus.SC_NOT_FOUND, "element not found");
}
final Cache cache = Cache.from(inMemory);
response.getWriter().write(cache.toString());
}
示例5: get
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
public Object get(final String key) {
final Object[] count = new Object[1];
count[0] = null;
final RetryingExecutor executor = new RetryingExecutor(3, 500, new IClosure() {
public void execute(final Object arg0) throws Exception {
final MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
count[0] = memcache.get(key);
}
}, null);
try {
executor.startExecution();
} catch (final Throwable e) {
log.log(Level.WARNING, "Problems when getting object from MemCache. Key [" + key + "]: " + e.getMessage(), e);
}
return count[0];
}
示例6: findByBuildTypeIdOrderByBuildIdDesc
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
/**
* Finds the {@code TestReport} with the given build type id ordered by build id in the descendant order.
*
* @param buildTypeId the build type id.
* @param limit the optional fetch limit, by default {@link com.google.appengine.tck.site.endpoints.TestReport#DEFAULT_FETCH_LIMIT}.
* @param reports the reports entry point
* @return the matching test reports list or an empty one if none.
*/
@SuppressWarnings("unchecked")
public static List<TestReport> findByBuildTypeIdOrderByBuildIdDesc(String buildTypeId, Optional<Integer> limit, Reports reports) {
final MemcacheService memcacheService = reports.getMemcacheService();
List<TestReport> results = (List<TestReport>) memcacheService.get(buildTypeId);
if (results == null) {
final Filter buildTypeFilter = new Query.FilterPredicate("buildTypeId", FilterOperator.EQUAL, buildTypeId);
final Query query = new Query(TEST_REPORT).setFilter(buildTypeFilter).addSort("buildId", DESCENDING);
final DatastoreService datastoreService = reports.getDatastoreService();
final PreparedQuery preparedQuery = datastoreService.prepare(query);
final List<Entity> entities = preparedQuery.asList(FetchOptions.Builder.withLimit(limit.or(DEFAULT_FETCH_LIMIT)));
results = new ArrayList<>();
for (Entity oneEntity : entities) {
final TestReport report = from(oneEntity);
results.add(report);
}
memcacheService.put(buildTypeId, results);
}
return results;
}
示例7: getBlobFromCache
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Override
protected <T extends I_Blob> I_Blob getBlobFromCache(String generatedKey, Class<? extends T> blobType) throws BlobException
{
MemcacheService memCache = MemcacheServiceFactory.getMemcacheService();
byte[] blobBytes = null;
try
{
blobBytes = (byte[]) memCache.get(generatedKey);
}
catch(Exception e)
{
s_logger.log(Level.WARNING, "Could not get value from memcache.", e);
}
if( blobBytes != null )
{
I_Blob blob = U_Blob.createBlobInstance(blobType);
U_Blob.readBytes(blob, blobBytes);
return blob;
}
return null;
}
示例8: getRequestHash
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
private RequestHash getRequestHash(String requestUri) {
final MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
RequestHash requestHash = (RequestHash) syncCache.get(requestUri);
if (requestHash == null) {
final PersistenceManager pm = PMF.get().getPersistenceManager();
final Query query = pm.newQuery(RequestHash.class);
query.setFilter("requestUri == requestUriParam");
query.declareParameters("String requestUriParam");
query.setUnique(true);
try {
requestHash = (RequestHash) query.execute(requestUri);
if (requestHash != null) {
syncCache.put(requestUri, requestHash, Expiration.byDeltaSeconds(180));
}
} finally {
query.closeAll();
}
}
return requestHash;
}
示例9: getLangaugeLabel
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
public String getLangaugeLabel(String lang){
String key = "lang:" + this.target + ":" + lang;
String result = "";
// Using the synchronous cache
MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
//syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
result = (String) syncCache.get(key); // read from cache
if (result == null) {
System.out.println("Cache miss");
Hashtable<String, String> hash = getLanguagesFromAPI();
result = hash.get(lang);
// populate cache
Enumeration<String> en = hash.keys();
while(en.hasMoreElements()){
String code = en.nextElement();
String tempkey = "lang:" + this.target + ":" + code;
syncCache.put(tempkey, hash.get(code));
}
} else{
System.out.println("Cache hit");
}
return result;
}
示例10: doGet
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
String path = req.getRequestURI();
if (path.startsWith("/favicon.ico")) {
return; // ignore the request for favicon.ico
}
MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
String key = "count-sync";
byte[] value;
long count = 1;
value = (byte[]) syncCache.get(key);
if (value == null) {
value = BigInteger.valueOf(count).toByteArray();
syncCache.put(key, value);
} else {
// Increment value
count = new BigInteger(value).longValue();
count++;
value = BigInteger.valueOf(count).toByteArray();
// Put back in cache
syncCache.put(key, value);
}
// Output content
resp.setContentType("text/plain");
resp.getWriter().print("Value is " + count + "\n");
}
示例11: getKeys
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
/**
* Returns possible cached result of a query.
*
* @param <T>
* datastore object class
* @param ofy
* Objectify
* @param q
* a query
* @param cacheSuffix
* suffix for the cache key
* @return possible cached result of the query
*/
public static <T> List<Key<T>> getKeys(Objectify ofy,
com.googlecode.objectify.Query<T> q, String cacheSuffix) {
String key = q.toString() + cacheSuffix;
MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
syncCache.setErrorHandler(ErrorHandlers
.getConsistentLogAndContinue(Level.INFO));
String value = (String) syncCache.get(key); // read from cache
List<Key<T>> result;
if (value == null) {
result = q.listKeys();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < result.size(); i++) {
if (i != 0)
sb.append(' ');
sb.append(result.get(i).getString());
}
value = sb.toString();
syncCache.put(key, value); // populate cache
} else {
List<String> keys = NWUtils.split(value, ' ');
result = new ArrayList<Key<T>>();
for (String k : keys) {
result.add(new Key<T>(k));
}
}
return result;
}
示例12: getDataVersion
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
/**
* @return current data version
*/
public static long getDataVersion() {
MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
syncCache.setErrorHandler(ErrorHandlers
.getConsistentLogAndContinue(Level.INFO));
Long v = (Long) syncCache.get("DataVersion");
if (v == null) {
syncCache.put("DataVersion", 1L);
v = 1L;
}
return v;
}
示例13: getAnnouncement
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@ApiMethod(
name = "getAnnouncement",
path = "announcement",
httpMethod = HttpMethod.GET
)
public Announcement getAnnouncement() {
MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService();
Object message = memcacheService.get(Constants.MEMCACHE_ANNOUNCEMENTS_KEY);
if (message != null) {
return new Announcement(message.toString());
}
return null;
}
示例14: doGet
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public final void doGet(final HttpServletRequest req,
final HttpServletResponse resp)
throws IOException {
// First retrieve messages from the memcache
MemcacheService memcacheService = MemcacheServiceFactory
.getMemcacheService();
List<String> messages =
(List<String>) memcacheService.get(Constants.MESSAGE_CACHE_KEY);
if (messages == null) {
// If no messages in the memcache, look for the datastore
DatastoreService datastore =
DatastoreServiceFactory.getDatastoreService();
PreparedQuery query = datastore.prepare(
new Query("PubsubMessage").addSort("receipt-time",
Query.SortDirection.DESCENDING));
messages = new ArrayList<>();
for (Entity entity : query.asIterable(
FetchOptions.Builder.withLimit(MAX_COUNT))) {
String message = (String) entity.getProperty("message");
messages.add(message);
}
// Store them to the memcache for future use.
memcacheService.put(Constants.MESSAGE_CACHE_KEY, messages);
}
ObjectMapper mapper = new ObjectMapper();
resp.setContentType("application/json; charset=UTF-8");
mapper.writeValue(resp.getWriter(), messages);
resp.getWriter().close();
}
示例15: getAnnouncement
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@ApiMethod(
name = "getAnnouncement",
path = "announcement",
httpMethod = HttpMethod.GET
)
public Announcement getAnnouncement() {
MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService();
String announcementKey = Constants.MEMCACHE_ANNOUNCEMENTS_KEY;
Object message = memcacheService.get(announcementKey);
if (message != null) {
return new Announcement(message.toString());
}
return null;
}