本文整理汇总了Java中net.spy.memcached.CASMutation类的典型用法代码示例。如果您正苦于以下问题:Java CASMutation类的具体用法?Java CASMutation怎么用?Java CASMutation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CASMutation类属于net.spy.memcached包,在下文中一共展示了CASMutation类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DaddFullAction
import net.spy.memcached.CASMutation; //导入依赖的package包/类
public void DaddFullAction(String clientName,final Action a)
{
if (logger.isDebugEnabled())
logger.debug("Adding full action to cache for "+a.getUserId()+" item "+a.getItemId());
CASMutation<List<Action>> mutation = new CASMutation<List<Action>>() {
// This is only invoked when a value actually exists.
public List<Action> getNewValue(List<Action> current) {
current.add(0, a);
return current;
}
};
List<Action> actions = new ArrayList<Action>();
actions.add(a);
String mkey = MemCacheKeys.getActionFullHistory(clientName, a.getUserId());
MemCachePeer.cas(mkey, mutation, actions,CACHE_TIME);
}
示例2: DaddAction
import net.spy.memcached.CASMutation; //导入依赖的package包/类
public void DaddAction(String clientName,long userId,final long itemId) throws APIException
{
if (logger.isDebugEnabled())
logger.debug("Adding action to cache for "+userId+" item "+itemId);
CASMutation<List<Long>> mutation = new CASMutation<List<Long>>() {
// This is only invoked when a value actually exists.
public List<Long> getNewValue(List<Long> current) {
if(!current.contains(itemId)) {
current.add(0, itemId);
}
return current;
}
};
List<Long> actions = new ArrayList<>();
actions.add(itemId);
String mkey = MemCacheKeys.getActionHistory(clientName, userId);
MemCachePeer.cas(mkey, mutation, actions,CACHE_TIME);
}
示例3: addFullAction
import net.spy.memcached.CASMutation; //导入依赖的package包/类
@Override
public void addFullAction(String clientName,final Action a)
{
if (logger.isDebugEnabled())
logger.debug("Adding full action to cache for "+a.getUserId()+" item "+a.getItemId());
CASMutation<List<Action>> mutation = new CASMutation<List<Action>>() {
// This is only invoked when a value actually exists.
public List<Action> getNewValue(List<Action> current) {
current.add(0, a);
return current;
}
};
List<Action> actions = new ArrayList<Action>();
actions.add(a);
String mkey = MemCacheKeys.getActionFullHistory(clientName, a.getUserId());
cacheClient.cas(mkey, mutation, actions,CACHE_TIME);
}
示例4: addAction
import net.spy.memcached.CASMutation; //导入依赖的package包/类
@Override
public void addAction(String clientName,long userId,final long itemId) throws APIException
{
if (logger.isDebugEnabled())
logger.debug("Adding action to cache for "+userId+" item "+itemId);
CASMutation<List<Long>> mutation = new CASMutation<List<Long>>() {
// This is only invoked when a value actually exists.
public List<Long> getNewValue(List<Long> current) {
if(!current.contains(itemId)) {
current.add(0, itemId);
}
return current;
}
};
List<Long> actions = new ArrayList<>();
actions.add(itemId);
String mkey = MemCacheKeys.getActionHistory(clientName, userId);
cacheClient.cas(mkey, mutation, actions,CACHE_TIME);
}
示例5: cas
import net.spy.memcached.CASMutation; //导入依赖的package包/类
/**
* Method to allow CAS
* @param <T>
* @param key
* @param mutation
* @param value
* @return
*/
public <T> T cas(String key,CASMutation<T> mutation,T value,int expireSecs)
{
Transcoder transcoder = new SerializingTranscoder();
// The mutator who'll do all the low-level stuff.
// Set number of retries to limit time taken..its not essential this succeeds
CASMutator<T> mutator = new CASMutator<>(memcachedClient, transcoder,MAX_CAS_RETRIES);
// This returns whatever value was successfully stored within the
// cache -- either the initial list as above, or a mutated existing
// one
try
{
return mutator.cas(hashKey(key), value, expireSecs, mutation);
}
catch (Exception e)
{
logger.error("Failed up update hits in cache ",e);
return null;
}
}
示例6: cas
import net.spy.memcached.CASMutation; //导入依赖的package包/类
/**
* Method to allow CAS
* @param <T>
* @param key
* @param mutation
* @param value
* @return
*/
public static <T> T cas(String key,CASMutation<T> mutation,T value,int expireSecs)
{
MemcachedClient client = getClient();
if (client != null)
{
Transcoder transcoder = new SerializingTranscoder();
// The mutator who'll do all the low-level stuff.
// Set number of retries to limit time taken..its not essential this succeeds
CASMutator<T> mutator = new CASMutator<>(client, transcoder,MAX_CAS_RETRIES);
// This returns whatever value was successfully stored within the
// cache -- either the initial list as above, or a mutated existing
// one
try
{
return mutator.cas(hashKey(key), value, expireSecs, mutation);
}
catch (Exception e)
{
logger.error("Failed up update hits in cache ",e);
return null;
}
}
else
return null;
}
示例7: testStart
import net.spy.memcached.CASMutation; //导入依赖的package包/类
public void testStart() throws Exception {
String testKey = "TEST_PREFIX:TEST_KEY";
String testValue = "TEST_VALUE";
Integer expireTime = 4; // 4초
arcusClient.delete(testKey); // 아커스 내 test value clear
CASMutation<String> mutation = new CASMutation<String>() {
@Override
public String getNewValue(String current) {
return current;
}
};
CASMutator<String> mutator = new CASMutator(arcusClient, new SerializingTranscoder());
mutator.cas(testKey, testValue, expireTime, mutation); //값이 없으므로 add
mutator.cas(testKey, testValue, expireTime, mutation); // 다시 call하여 update 시킨다, 값이 살아있을 때 업데이트 되는 상황
CollectionFuture<CollectionAttributes> attrs = arcusClient.asyncGetAttr(testKey);
Thread.sleep(6000); // 6초후 수행 expire time 초과시킨다
String result = (String)arcusClient.get(testKey);
System.out.println(attrs.get().getExpireTime());
System.out.println(result);
}
示例8: testCAS
import net.spy.memcached.CASMutation; //导入依赖的package包/类
@Test public void testCAS() throws Exception {
String key = "testCAS";
Transcoder tc = new SerializingTranscoder();
CASMutator<String> mutator=new CASMutator<String>(client, tc);
CASMutation<String> mutation=new CASMutation<String>() {
public String getNewValue(String current) {
return current + current;
}
};
// Do a mutation.
String currentValue=mutator.cas(key, "Wibble", 10000, mutation);
currentValue=mutator.cas(key, "Wibble", 10000, mutation);
assertEquals("WibbleWibble", currentValue);
}