当前位置: 首页>>代码示例>>Java>>正文


Java Expiration类代码示例

本文整理汇总了Java中com.google.appengine.api.memcache.Expiration的典型用法代码示例。如果您正苦于以下问题:Java Expiration类的具体用法?Java Expiration怎么用?Java Expiration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Expiration类属于com.google.appengine.api.memcache包,在下文中一共展示了Expiration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUserName

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
@Override
public void setUserName(final String userId, final String name) {
  try {
    runJobWithRetries(new JobRetryHelper() {
      @Override
      public void run(Objectify datastore) {
        UserData userData = datastore.find(userKey(userId));
        if (userData != null) {
          userData.name = name;
          datastore.put(userData);
        }
        // we need to change the memcache version of user
        User user = new User(userData.id,userData.email,name, userData.link, userData.emailFrequency, userData.tosAccepted,
            false, userData.type, userData.sessionid);
        String cachekey = User.usercachekey + "|" + userId;
        memcache.put(cachekey, user, Expiration.byDeltaSeconds(60)); // Remember for one minute
      }
    }, true);
  } catch (ObjectifyException e) {
    throw CrashReport.createAndLogError(LOG, null, collectUserErrorInfo(userId), e);
  }

}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:24,代码来源:ObjectifyStorageIo.java

示例2: setUserLink

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
@Override
public void setUserLink(final String userId, final String link) {
  try {
    runJobWithRetries(new JobRetryHelper() {
      @Override
      public void run(Objectify datastore) {
        UserData userData = datastore.find(userKey(userId));
        if (userData != null) {
          userData.link = link;
          datastore.put(userData);
        }
        // we need to change the memcache version of user
        User user = new User(userData.id,userData.email,userData.name,link,userData.emailFrequency,userData.tosAccepted,
            false, userData.type, userData.sessionid);
        String cachekey = User.usercachekey + "|" + userId;
        memcache.put(cachekey, user, Expiration.byDeltaSeconds(60)); // Remember for one minute
      }
    }, true);
  } catch (ObjectifyException e) {
    throw CrashReport.createAndLogError(LOG, null, collectUserErrorInfo(userId), e);
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:23,代码来源:ObjectifyStorageIo.java

示例3: setUserEmailFrequency

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
@Override
public void setUserEmailFrequency(final String userId, final int emailFrequency) {
  try {
    runJobWithRetries(new JobRetryHelper() {
      @Override
      public void run(Objectify datastore) {
        UserData userData = datastore.find(userKey(userId));
        if (userData != null) {
          userData.emailFrequency = emailFrequency;
          datastore.put(userData);
        }
        // we need to change the memcache version of user
        User user = new User(userData.id,userData.email,userData.name,userData.link,emailFrequency,userData.tosAccepted,
            false, userData.type, userData.sessionid);
        String cachekey = User.usercachekey + "|" + userId;
        memcache.put(cachekey, user, Expiration.byDeltaSeconds(60)); // Remember for one minute
      }
    }, true);
  } catch (ObjectifyException e) {
    throw CrashReport.createAndLogError(LOG, null, collectUserErrorInfo(userId), e);
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:23,代码来源:ObjectifyStorageIo.java

示例4: putIfUntouched

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
/**
 * NOTE: This differs from {@link MemcacheService} in that it allows oldValue
 * to be null, in which case it will put unconditionally.
 */
public boolean putIfUntouched(@Nullable K key, IdentifiableValue<V> oldValue,
    @Nullable V newValue, @Nullable Expiration expires) {
  TaggedKey<K> taggedKey = tagKey(key);
  String expiresString = expires == null ? null : "" + expires.getMillisecondsValue();
  boolean result;
  if (oldValue == null) {
    service.put(taggedKey, newValue, expires);
    result = true;
  } else {
    result = service.putIfUntouched(taggedKey, oldValue.inner, newValue, expires);
  }
  log.info("cache putIfUntouched " + taggedKey + " = " + newValue
      + ", " + expiresString + ": " + result);
  return result;
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:20,代码来源:MemcacheTable.java

示例5: testPutIfUntouchedExpire

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
@Test
public void testPutIfUntouchedExpire() {
    final String TS_KEY = createTimeStampKey("testPutIfUntouched");

    memcache.put(TS_KEY, STR_VALUE);
    MemcacheService.IdentifiableValue oldOriginalIdValue = memcache.getIdentifiable(TS_KEY);
    final String NEW_VALUE = "new-" + STR_VALUE;

    // Store NEW_VALUE if no other value stored since oldOriginalIdValue was retrieved.
    // memcache.get() has not been called, so this put should succeed.
    Boolean valueWasStored = memcache.putIfUntouched(TS_KEY, oldOriginalIdValue, NEW_VALUE, Expiration.byDeltaSeconds(1));
    assertEquals(true, valueWasStored);
    assertEquals(NEW_VALUE, memcache.get(TS_KEY));

    // Value should not be stored after expiration period.
    sync(3000);
    assertNull(memcache.get(TS_KEY));
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:19,代码来源:MemcacheTest.java

示例6: testPutIfUntouchedExpire

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
@Test
public void testPutIfUntouchedExpire() {
    final String TS_KEY = createTimeStampKey("testPutIfUntouched");

    memcache.put(TS_KEY, STR_VALUE);
    IdentifiableValue oldOriginalIdValue = memcache.getIdentifiable(TS_KEY);
    final String NEW_VALUE = "new-" + STR_VALUE;
    Future<Boolean> future;
    Boolean valueWasStored;

    // Store NEW_VALUE if no other value stored since oldOriginalIdValue was retrieved.
    // memcache.get() has not been called, so this put should succeed.
    future = asyncMemcache.putIfUntouched(TS_KEY, oldOriginalIdValue, NEW_VALUE, Expiration.byDeltaSeconds(1));
    valueWasStored = waitOnFuture(future);
    assertEquals(true, valueWasStored);
    assertEquals(NEW_VALUE, memcache.get(TS_KEY));

    // Value should not be stored after expiration period.
    sync(3000);
    assertNull(memcache.get(TS_KEY));
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:22,代码来源:MemcacheAsync2Test.java

示例7: getCount

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
/**
 * Retrieve the value of this sharded counter.
 *
 * @return Summed total of all shards' counts
 */
public long getCount() {
  Long value = (Long) mc.get(kind);
  if (value != null) {
    return value;
  }

  long sum = 0;
  Query query = new Query(kind);
  for (Entity shard : ds.prepare(query).asIterable()) {
    sum += (Long) shard.getProperty(CounterShard.COUNT);
  }
  mc.put(kind, sum, Expiration.byDeltaSeconds(60),
      SetPolicy.ADD_ONLY_IF_NOT_PRESENT);

  return sum;
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-sharded-counters-java-maven,代码行数:22,代码来源:ShardedCounter.java

示例8: getCount

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
/**
 * Retrieve the value of this sharded counter.
 *
 * @return Summed total of all shards' counts
 */
public final long getCount() {
    Long value = (Long) mc.get(kind);
    if (value != null) {
        return value;
    }

    long sum = 0;
    Query query = new Query(kind);
    for (Entity shard : DS.prepare(query).asIterable()) {
        sum += (Long) shard.getProperty(CounterShard.COUNT);
    }
    mc.put(kind, sum, Expiration.byDeltaSeconds(CACHE_PERIOD),
            SetPolicy.ADD_ONLY_IF_NOT_PRESENT);

    return sum;
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-sharded-counters-java,代码行数:22,代码来源:ShardedCounter.java

示例9: putIfUntouched

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
/**
 * NOTE: This differs from {@link MemcacheService} in that it allows oldValue to be null, in which
 * case it will put unconditionally.
 */
public boolean putIfUntouched(@Nullable K key, IdentifiableValue<V> oldValue,
    @Nullable V newValue, @Nullable Expiration expires) {
  TaggedKey<K> taggedKey = tagKey(key);
  String expiresString = expires == null ? null : "" + expires.getMillisecondsValue();
  boolean result;
  if (oldValue == null) {
    service.put(taggedKey, newValue, expires);
    result = true;
  } else {
    result = service.putIfUntouched(taggedKey, oldValue.inner, newValue, expires);
  }
  log.info("cache putIfUntouched " + taggedKey + " = " + newValue + ", " + expiresString + ": "
      + result);
  return result;
}
 
开发者ID:larrytin,项目名称:realtime-server-appengine,代码行数:20,代码来源:MemcacheTable.java

示例10: tokenFor

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
private String tokenFor(Session session) {
  String sessionId = session.sessionId;
  if (sessionId.charAt(0) != Platform.WEB.prefix()) {
    return null;
  }
  String existing = clientTokens.get(sessionId);
  if (existing != null) {
    log.info("Got existing token for client " + session + ": " + existing);
    return existing;
  }

  // This might screw up a concurrent attempt to do the same thing but
  // doesn't really matter.
  String token = channelService.createChannel(sessionId);
  clientTokens.put(sessionId, token, Expiration.byDeltaSeconds(ChannelExpirationSeconds));

  log.info("Got new token for client " + session + ": " + token);
  return token;
}
 
开发者ID:larrytin,项目名称:realtime-server-appengine,代码行数:20,代码来源:SlobMessageRouter.java

示例11: subscribe

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
private void subscribe(String sessionId, String docId) {
  log.config("Subscribing " + sessionId + " to " + docId);
  HashSet<String> docs = (HashSet<String>) listSessionSubscriptions(sessionId);
  if (docs == null) {
    docs = new HashSet<String>();
  }
  if (!docs.contains(docId)) {
    docs.add(docId);
    sessionDocs.put(sessionId, docs, Expiration.byDeltaSeconds(PresenceExpirationSeconds));
  }
  Platform platform = Platform.fromPrefix(sessionId.charAt(0));
  HashSet<String> sessions = (HashSet<String>) listDocumentSubscriptions(docId, platform.name());
  if (sessions == null) {
    sessions = new HashSet<String>();
  }
  if (!sessions.contains(sessionId)) {
    sessions.add(sessionId);
    MemcacheTable<String, HashSet<String>> docSessions = getCachedSessions(platform.name());
    docSessions.put(docId, sessions, Expiration.byDeltaSeconds(PresenceExpirationSeconds));
  }
}
 
开发者ID:larrytin,项目名称:realtime-server-appengine,代码行数:22,代码来源:PresenceEndpoint.java

示例12: getRequestHash

import com.google.appengine.api.memcache.Expiration; //导入依赖的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

示例13: doPost

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  PrintWriter out = resp.getWriter();
  BufferedReader input = new BufferedReader(new InputStreamReader(req.getInputStream()));
  String queryString = input.readLine();

  if (queryString == null) {
    out.println("queryString is null");
    return;
  }

  HashMap<String, String> params = getQueryMap(queryString);
  String key = params.get("key");
  if (key == null) {
    out.println("no key");
    return;
  }

  if (memcacheNotAvailable()) {
    String ipAddress = params.get("ipaddr");
    if (ipAddress == null) {  // Malformed request
      out.println("no ipaddress");
      return;
    }
    storageIo.storeIpAddressByKey(key, ipAddress);
    out.println("OK (Datastore)");
    return;
  }

  memcache.put(rendezvousuuid + key, params, Expiration.byDeltaSeconds(300));
  out.println("OK");
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:32,代码来源:RendezvousServlet.java

示例14: getMotd

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
/**
 * Gets the current Motd
 *
 * @return  the current Motd
 */
@Override
public Motd getMotd() {

  Motd motd = (Motd) memcache.get(motdcachekey); // Attempt to use memcache to fetch it
  if (motd != null)
    return motd;

  motd = storageIo.getCurrentMotd();
  memcache.put(motdcachekey, motd, Expiration.byDeltaSeconds(600)); // Hold it for ten minutes
  return motd;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:17,代码来源:GetMotdServiceImpl.java

示例15: put

import com.google.appengine.api.memcache.Expiration; //导入依赖的package包/类
/**
 * @return true if a new entry was created, false if not because of the
 *         policy.
 */
public boolean put(@Nullable K key, @Nullable V value, @Nullable Expiration expires,
    SetPolicy policy) {
  TaggedKey<K> taggedKey = tagKey(key);
  String expiresString = expires == null ? null : "" + expires.getMillisecondsValue();
  log.info("cache put " + taggedKey + " = " + value + ", " + expiresString + ", " + policy);
  return service.put(taggedKey, value, expires, policy);
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:12,代码来源:MemcacheTable.java


注:本文中的com.google.appengine.api.memcache.Expiration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。