本文整理匯總了Java中com.google.appengine.api.memcache.MemcacheService.IdentifiableValue方法的典型用法代碼示例。如果您正苦於以下問題:Java MemcacheService.IdentifiableValue方法的具體用法?Java MemcacheService.IdentifiableValue怎麽用?Java MemcacheService.IdentifiableValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.appengine.api.memcache.MemcacheService
的用法示例。
在下文中一共展示了MemcacheService.IdentifiableValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getIdentifiable
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Nullable public IdentifiableValue<V> getIdentifiable(@Nullable K key) {
TaggedKey<K> taggedKey = tagKey(key);
MemcacheService.IdentifiableValue rawValue;
try {
rawValue = service.getIdentifiable(taggedKey);
} catch (InvalidValueException e) {
// Probably a deserialization error (incompatible serialVersionUID or similar).
log.log(Level.WARNING, "Error getting object from memcache, key: " + key, e);
return null;
}
if (rawValue == null) {
log.info("cache miss " + taggedKey);
return null;
} else {
log.info("cache hit " + taggedKey + " = " + rawValue);
return new IdentifiableValue<V>(rawValue);
}
}
示例2: put
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
public boolean put(Object key, long txTimestamp, Object value) {
String versionKey = versionKey(key);
// check for the current version cached
MemcacheService.IdentifiableValue currentVersion = memcacheService.getIdentifiable(versionKey);
if (!isNewer(currentVersion, txTimestamp)) {
return false;
}
// store the value first so we don't risk the version number appearing before the
// corresponding value is written
memcacheService.put(valueKey(key, txTimestamp), value);
// Now update the version key if a newer version hasn't already been stored
while (!updateVersionKey(versionKey, currentVersion, txTimestamp)) {
// ... in the meantime another process has updated the cache with a version
// but we don't know if it's older or younger, so we have to try again
currentVersion = memcacheService.getIdentifiable(versionKey);
}
return true;
}
示例3: testPutIfUntouchedExpire
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的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));
}
示例4: getIdentifiable
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Nullable
public IdentifiableValue<V> getIdentifiable(@Nullable K key) {
TaggedKey<K> taggedKey = tagKey(key);
MemcacheService.IdentifiableValue rawValue;
try {
rawValue = service.getIdentifiable(taggedKey);
} catch (InvalidValueException e) {
// Probably a deserialization error (incompatible serialVersionUID or similar).
log.log(Level.WARNING, "Error getting object from memcache, key: " + key, e);
return null;
}
if (rawValue == null) {
log.info("cache miss " + taggedKey);
return null;
} else {
log.info("cache hit " + taggedKey + " = " + rawValue);
return new IdentifiableValue<V>(rawValue);
}
}
示例5: updateVersionKey
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
private boolean updateVersionKey(String versionKey, MemcacheService.IdentifiableValue currentVersion, long txTimestamp) {
if (currentVersion == null) {
// No existing version...
return memcacheService.put(versionKey,
txTimestamp,
versionExpiration(),
MemcacheService.SetPolicy.ADD_ONLY_IF_NOT_PRESENT);
} else {
return memcacheService.putIfUntouched(
versionKey,
currentVersion,
txTimestamp,
versionExpiration());
}
}
示例6: isNewer
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
private boolean isNewer(MemcacheService.IdentifiableValue currentVersion, long newVersion) {
if (currentVersion == null) {
return true;
}
Number currentVersionNumber = (Number) currentVersion.getValue();
return currentVersionNumber.longValue() < newVersion;
}
示例7: testGetIdentifiables
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Test
public void testGetIdentifiables() {
unwrap(service.put("key1", "value1"));
unwrap(service.put("key2", "value2"));
Map<String, MemcacheService.IdentifiableValue> identifiables = unwrap(service.getIdentifiables(Arrays.asList("key1", "key2")));
assertEquals(2, identifiables.size());
assertNotNull(identifiables.get("key1"));
assertEquals("value1", identifiables.get("key1").getValue());
assertNotNull(identifiables.get("key2"));
assertEquals("value2", identifiables.get("key2").getValue());
}
示例8: testPutIfUntouched
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Test
public void testPutIfUntouched() {
unwrap(service.put("key", "value"));
MemcacheService.IdentifiableValue identifiable = unwrap(service.getIdentifiable("key"));
boolean valueWasStored = unwrap(service.putIfUntouched("key", identifiable, "newValue"));
assertTrue(valueWasStored);
assertEquals("newValue", unwrap(service.get("key")));
boolean valueWasStored2 = unwrap(service.putIfUntouched("key", identifiable, "newestValue"));
assertFalse(valueWasStored2);
assertEquals("newValue", unwrap(service.get("key")));
}
示例9: testPutIfUntouchedMulti
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Test
public void testPutIfUntouchedMulti() {
unwrap(service.put("key1", "value1"));
unwrap(service.put("key2", "value2"));
MemcacheService.IdentifiableValue identifiable1 = unwrap(service.getIdentifiable("key1"));
MemcacheService.IdentifiableValue identifiable2 = unwrap(service.getIdentifiable("key2"));
HashMap<Object, MemcacheService.CasValues> map = new HashMap<Object, MemcacheService.CasValues>();
map.put("key1", new MemcacheService.CasValues(identifiable1, "newValue1"));
map.put("key2", new MemcacheService.CasValues(identifiable2, "newValue2"));
Set<Object> storedKeys = unwrap(service.putIfUntouched(map));
assertEquals(2, storedKeys.size());
assertTrue(storedKeys.contains("key1"));
assertTrue(storedKeys.contains("key2"));
assertEquals("newValue1", unwrap(service.get("key1")));
assertEquals("newValue2", unwrap(service.get("key2")));
map = new HashMap<Object, MemcacheService.CasValues>();
map.put("key1", new MemcacheService.CasValues(identifiable1, "newestValue1"));
map.put("key2", new MemcacheService.CasValues(identifiable1, "newestValue2"));
storedKeys = unwrap(service.putIfUntouched(map));
assertTrue(storedKeys.isEmpty());
assertEquals("newValue1", unwrap(service.get("key1")));
assertEquals("newValue2", unwrap(service.get("key2")));
}
示例10: testGetIdentifiables
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Test
public void testGetIdentifiables() {
memcache.put("key1", "value1");
memcache.put("key2", "value2");
Map<String, MemcacheService.IdentifiableValue> identifiables = memcache.getIdentifiables(Arrays.asList("key1", "key2"));
assertEquals(2, identifiables.size());
assertNotNull(identifiables.get("key1"));
assertEquals("value1", identifiables.get("key1").getValue());
assertNotNull(identifiables.get("key2"));
assertEquals("value2", identifiables.get("key2").getValue());
}
示例11: testGetSomeIdentifiables
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Test
public void testGetSomeIdentifiables() {
memcache.put("key1", "value1");
Map<String, MemcacheService.IdentifiableValue> identifiables = memcache.getIdentifiables(Arrays.asList("key1", "no_such_key2"));
assertEquals(1, identifiables.size());
assertNotNull(identifiables.get("key1"));
assertEquals("value1", identifiables.get("key1").getValue());
}
示例12: testPutIfUntouched
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Test
public void testPutIfUntouched() {
memcache.put("key", "value");
MemcacheService.IdentifiableValue identifiable = memcache.getIdentifiable("key");
boolean valueWasStored = memcache.putIfUntouched("key", identifiable, "newValue");
assertTrue(valueWasStored);
assertEquals("newValue", memcache.get("key"));
boolean valueWasStored2 = memcache.putIfUntouched("key", identifiable, "newestValue");
assertFalse(valueWasStored2);
assertEquals("newValue", memcache.get("key"));
}
示例13: testPutIfUntouchedMulti
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Test
public void testPutIfUntouchedMulti() {
memcache.put("key1", "value1");
memcache.put("key2", "value2");
MemcacheService.IdentifiableValue identifiable1 = memcache.getIdentifiable("key1");
MemcacheService.IdentifiableValue identifiable2 = memcache.getIdentifiable("key2");
HashMap<Object, MemcacheService.CasValues> map = new HashMap<Object, MemcacheService.CasValues>();
map.put("key1", new MemcacheService.CasValues(identifiable1, "newValue1"));
map.put("key2", new MemcacheService.CasValues(identifiable2, "newValue2"));
Set<Object> storedKeys = memcache.putIfUntouched(map);
assertEquals(2, storedKeys.size());
assertTrue(storedKeys.contains("key1"));
assertTrue(storedKeys.contains("key2"));
assertEquals("newValue1", memcache.get("key1"));
assertEquals("newValue2", memcache.get("key2"));
map = new HashMap<Object, MemcacheService.CasValues>();
map.put("key1", new MemcacheService.CasValues(identifiable1, "newestValue1"));
map.put("key2", new MemcacheService.CasValues(identifiable1, "newestValue2"));
storedKeys = memcache.putIfUntouched(map);
assertTrue(storedKeys.isEmpty());
assertEquals("newValue1", memcache.get("key1"));
assertEquals("newValue2", memcache.get("key2"));
}
示例14: IdentifiableValue
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
IdentifiableValue(MemcacheService.IdentifiableValue inner) {
this.inner = checkNotNull(inner, "Null inner");
}
示例15: testGetIdentifiable
import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Test
public void testGetIdentifiable() {
unwrap(service.put("key", "value"));
MemcacheService.IdentifiableValue identifiable = unwrap(service.getIdentifiable("key"));
assertEquals("value", identifiable.getValue());
}