當前位置: 首頁>>代碼示例>>Java>>正文


Java MemcacheServiceFactory類代碼示例

本文整理匯總了Java中com.google.appengine.api.memcache.MemcacheServiceFactory的典型用法代碼示例。如果您正苦於以下問題:Java MemcacheServiceFactory類的具體用法?Java MemcacheServiceFactory怎麽用?Java MemcacheServiceFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MemcacheServiceFactory類屬於com.google.appengine.api.memcache包,在下文中一共展示了MemcacheServiceFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: detect

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的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;
	
}
 
開發者ID:tpryan,項目名稱:Atlassian-Connect-Add-On-Starter-Kit-for-App-Engine,代碼行數:23,代碼來源:Translate.java

示例2: doGet

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的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");
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:22,代碼來源:MemcacheBestPracticeServlet.java

示例3: countPackages

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的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;
}
 
開發者ID:tim-lebedkov,項目名稱:npackd-gae-web,代碼行數:25,代碼來源:NWUtils.java

示例4: doGet

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的package包/類
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
	
  	// Query for conferences with less than 5 seats lef
	Iterable<Conference> iterable = ofy().load().type(Conference.class)
	                .filter("seatsAvailable <", 5)
	                .filter("seatsAvailable >", 0);
    List<String> conferenceNames = new ArrayList<>(0);
    for (Conference conference : iterable) {
        conferenceNames.add(conference.getName());
    }
    if (conferenceNames.size() > 0) {
        StringBuilder announcementStringBuilder = new StringBuilder(
                "Last chance to attend! The following conferences are nearly sold out: ");
        Joiner joiner = Joiner.on(", ").skipNulls();
        announcementStringBuilder.append(joiner.join(conferenceNames));
        MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService();
        memcacheService.put(Constants.MEMCACHE_ANNOUNCEMENTS_KEY,
                announcementStringBuilder.toString());
    }
    response.setStatus(204);
}
 
開發者ID:udacity,項目名稱:ud859,代碼行數:24,代碼來源:SetAnnouncementServlet.java

示例5: doGet

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的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());
}
 
開發者ID:sylvek,項目名稱:sharemyposition,代碼行數:20,代碼來源:RetrievePositionServletImpl.java

示例6: doGet

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  try {
    URLFetchServiceFactory.getURLFetchService()
        .fetchAsync(new URL("http://www.example.com/asyncWithGet"))
        .get();
  } catch (Exception anythingMightGoWrongHere) {
    // fall through
  }
  URLFetchServiceFactory.getURLFetchService()
      .fetchAsync(new URL("http://www.example.com/asyncWithoutGet"));
  MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
  String randomKey = "" + Math.random();
  String randomValue = "" + Math.random();
  memcache.put(randomKey, randomValue);
  resp.setContentType("text/plain");
  resp.getOutputStream().println(randomKey);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-java-vm-runtime,代碼行數:19,代碼來源:AppstatsMonitoredServlet.java

示例7: aquire

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的package包/類
public boolean aquire() {
    MemcacheService memcache = MemcacheServiceFactory.getMemcacheService(ns);
    long start = System.currentTimeMillis();
    while (true) {
        if (memcache.increment(key, 1L, 0L) == 1L) {
            return true;
        }
        if (System.currentTimeMillis() - start > maxWait) {
            return false;
        }
        try {
            Thread.sleep(100L);
        } catch (InterruptedException e) {
        }
    }
}
 
開發者ID:feroult,項目名稱:yawp,代碼行數:17,代碼來源:Mutex.java

示例8: get

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的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];
}
 
開發者ID:ZupCat,項目名稱:simple-datastore,代碼行數:19,代碼來源:MemcacheManager.java

示例9: testNamespace

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的package包/類
@Test
public void testNamespace() {
    // memcache.setNamespace() is deprecated.
    MemcacheService otherMemcache = MemcacheServiceFactory.getMemcacheService("other");
    otherMemcache.clearAll();
    memcache.clearAll();

    String key = createTimeStampKey("testNamespace");
    otherMemcache.put(key, "default");
    assertNull("This key should not exist in the default namespace.", memcache.get(key));
    assertNotNull(otherMemcache.get(key));

    String key2 = createTimeStampKey("testNamespace2");
    memcache.put(key2, "default2");
    assertNull("This key should not exist in the other namespace.", otherMemcache.get(key2));
    assertNotNull(memcache.get(key2));
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-tck,代碼行數:18,代碼來源:MemcacheTest.java

示例10: testAsyncWithNamespace

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的package包/類
@Test
public void testAsyncWithNamespace() {
    String namespace = "namespace-123";

    AsyncMemcacheService ams = MemcacheServiceFactory.getAsyncMemcacheService(namespace);

    String key = "some-random-key";
    String value = "some-random-value";

    waitOnFuture(ams.put(key, value));

    // non-namespaced lookup
    Assert.assertFalse(memcache.contains(key));

    MemcacheService ms = MemcacheServiceFactory.getMemcacheService(namespace);
    Assert.assertEquals(value, ms.get(key));
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-tck,代碼行數:18,代碼來源:MemcacheAsync2Test.java

示例11: putBlobIntoCache

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的package包/類
@Override
protected void putBlobIntoCache(String generatedKey, I_Blob blob) throws BlobException
{
	AsyncMemcacheService memCache = MemcacheServiceFactory.getAsyncMemcacheService();
	
	byte[] blobBytes = U_Blob.convertToBytes(blob);
	
	try
	{
		memCache.put(generatedKey, blobBytes, null, MemcacheService.SetPolicy.SET_ALWAYS);
	}
	catch(Exception e)
	{
		s_logger.log(Level.WARNING, "Could not put value into memcache.", e);
	}
}
 
開發者ID:dougkoellmer,項目名稱:swarm,代碼行數:17,代碼來源:BlobManager_MemCache.java

示例12: getBlobFromCache

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的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;
}
 
開發者ID:dougkoellmer,項目名稱:swarm,代碼行數:27,代碼來源:BlobManager_MemCache.java

示例13: getRequestHash

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的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;
}
 
開發者ID:devoxx,項目名稱:mobile-client,代碼行數:23,代碼來源:RequestMD5KeyServlet.java

示例14: doGet

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的package包/類
public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws IOException {
	final PersistenceManager pm = PMF.get().getPersistenceManager();

	final Query query = pm.newQuery(RequestHash.class);
	try {
		List<RequestHash> results = (List<RequestHash>) query.execute();
		for (RequestHash requestHash : results) {
			final Md5Calculator md5Calculator = new Md5Calculator(
					requestHash.getRequestUri());
			final String newMd5 = md5Calculator.calculateMd5();
			if (newMd5 != null && !newMd5.equals(requestHash.getMd5())) {
				requestHash.setMd5(newMd5);
				requestHash.setDate(new Date());
				pm.makePersistent(requestHash);

				final MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
				syncCache.delete(requestHash.getRequestUri());
			}
		}
	} finally {
		query.closeAll();
		pm.close();
	}
}
 
開發者ID:devoxx,項目名稱:mobile-client,代碼行數:26,代碼來源:RecalculateMD5KeysServlet.java

示例15: star

import com.google.appengine.api.memcache.MemcacheServiceFactory; //導入依賴的package包/類
public static Session star(Session session, boolean clearCache) {
	if (clearCache) {
		final String email = DataStore.getUserEmail();
		if (email != null) {
			final MemcacheService syncCache = MemcacheServiceFactory
					.getMemcacheService();
			syncCache.delete(email);
		}
	}

	final String sessionId = session.getSessionId();
	Session sessionDb = db.find(sessionId);
	if (sessionDb == null) {
		session.setEmailAddress(DataStore.getUserEmail());
		session = db.update(session);
	}
	UserService userService = UserServiceFactory.getUserService();
	User user = userService.getCurrentUser();
	C2DMMessage.enqueueStarSessionMessage(RequestFactoryServlet
			.getThreadLocalRequest().getSession().getServletContext(),
			user.getEmail(), sessionId);
	return session;
}
 
開發者ID:devoxx,項目名稱:mobile-client,代碼行數:24,代碼來源:DevoxxService.java


注:本文中的com.google.appengine.api.memcache.MemcacheServiceFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。