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


Java CASMutation類代碼示例

本文整理匯總了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);
	
}
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:19,代碼來源:ActionHistoryCache.java

示例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);
  }
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:20,代碼來源:ActionHistoryCache.java

示例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);
	
}
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:20,代碼來源:MemcacheActionHistory.java

示例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);
   }
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:21,代碼來源:MemcacheActionHistory.java

示例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;
	}
}
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:29,代碼來源:ExceptionSwallowingMemcachedClient.java

示例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;
}
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:35,代碼來源:MemCachePeer.java

示例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);
}
 
開發者ID:naver,項目名稱:arcus-misc,代碼行數:28,代碼來源:CASMutatorExpireTest.java

示例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);
}
 
開發者ID:C2B2,項目名稱:memcached-4-coherence,代碼行數:16,代碼來源:BasicIT.java


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