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


Java Cache.get方法代碼示例

本文整理匯總了Java中org.springframework.cache.Cache.get方法的典型用法代碼示例。如果您正苦於以下問題:Java Cache.get方法的具體用法?Java Cache.get怎麽用?Java Cache.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.cache.Cache的用法示例。


在下文中一共展示了Cache.get方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testPut

import org.springframework.cache.Cache; //導入方法依賴的package包/類
@Test
public void testPut() throws Exception {
    Cache proxy = new ConcurrentMapCache("foo");
    proxy.put("bar", "value");
    proxy.put("baz", "value");
    FluuzCache fluuzCache = new FluuzCache(eventManager, proxy);
    eventManager.register(fluuzCache);
    Thread.sleep(2000);

    eventManager.evict("foo", "bar");

    Thread.sleep(2000);

    String value = null;
    ValueWrapper vw = proxy.get("bar");
    if (vw == null) {

    }
    System.out.println("->" + value);
}
 
開發者ID:ArawakCC,項目名稱:fluuz,代碼行數:21,代碼來源:RedisEventManagerTest.java

示例2: cachesValuesReturnedForQueryMethod

import org.springframework.cache.Cache; //導入方法依賴的package包/類
@Test
public void cachesValuesReturnedForQueryMethod() {

	User dave = new User();
	dave.setUsername("dmatthews");

	dave = repository.save(dave);

	User result = repository.findByUsername("dmatthews");
	assertThat(result, is(dave));

	// Verify entity cached
	Cache cache = cacheManager.getCache("byUsername");
	ValueWrapper wrapper = cache.get("dmatthews");
	assertThat(wrapper.get(), is((Object) dave));
}
 
開發者ID:Just-Fun,項目名稱:spring-data-examples,代碼行數:17,代碼來源:CachingRepositoryTests.java

示例3: updateCache

import org.springframework.cache.Cache; //導入方法依賴的package包/類
@AfterReturning ("@annotation(fr.gael.dhus.spring.cache.IncrementCache)")
public void updateCache (JoinPoint joinPoint)
{
   IncrementCache annotation = ((MethodSignature) joinPoint.getSignature ())
         .getMethod ().getAnnotation (IncrementCache.class);

   Cache cache = getCacheManager().getCache(annotation.name());
   if (cache != null)
   {
      synchronized (cache)
      {
         Integer old_value = cache.get (annotation.key (), Integer.class);
         cache.clear ();
         if (old_value == null)
         {
            return;
         }
         cache.put (annotation.key (), (old_value + annotation.value ()));
      }
   }
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:22,代碼來源:CacheAspectDefinition.java

示例4: cronTest

import org.springframework.cache.Cache; //導入方法依賴的package包/類
@Scheduled(cron = "0 59 23 * * ?")
	public void cronTest() {
		System.out.println("測試定時任務!");
		// 測試手動存儲cache
		Cache cache = cacheManager.getCache("hour");
		Integer xx = cache.get("x", new Callable<Integer>() {

			@Override
			public Integer call() throws Exception {
				return 111111;
			}
			
		});
		// 測試redis
//		redisTemplate.boundListOps("xxxx").leftPush("xxxx");
		
		// 測試注解
		testService.selectById(1L);
		testService.selectById(1L);
		testService.selectById(1L);
		
		logger.debug(xx);
		logger.debug(new Date());
	}
 
開發者ID:TomChen001,項目名稱:xmanager,代碼行數:25,代碼來源:TestTask.java

示例5: addProduct

import org.springframework.cache.Cache; //導入方法依賴的package包/類
/**
 * Updates caches after a product insertion.
 *
 * @param retObject object returned by the annotated method.
 */
@AfterReturning(
      pointcut = "@annotation(fr.gael.dhus.spring.cache.AddProduct)",
      returning = "retObject")
public void addProduct(Object retObject)
{
   if (retObject != null && retObject instanceof Product)
   {
      Product p = (Product) retObject;

      // add the given product in cache
      Cache cache = getCacheManager().getCache(PRODUCT_CACHE_NAME);
      synchronized (cache)
      {
         cache.evict(p.getId());
         cache.evict(p.getUuid());
         cache.putIfAbsent(p.getId(), p);
         cache.putIfAbsent(p.getUuid(), p);
      }

      // increment global 'product_count' and clear others key
      cache = getCacheManager().getCache(PRODUCT_COUNT_CACHE_NAME);
      synchronized (cache)
      {
         Integer oldValue = cache.get(PRODUCT_COUNT_TOTAL_KEY, Integer.class);
         if (oldValue != null)
         {
            cache.clear();
            cache.putIfAbsent(PRODUCT_COUNT_TOTAL_KEY, (oldValue + 1));
         }
      }

      // clear 'products' cache
      getCacheManager().getCache(PRODUCTS_CACHE_NAME).clear();
   }
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:41,代碼來源:CacheAspectDefinition.java

示例6: validateTmpUser

import org.springframework.cache.Cache; //導入方法依賴的package包/類
@Transactional (readOnly=false, propagation=Propagation.REQUIRED)
public void validateTmpUser (String code)
{
   User u = userDao.getUserFromUserCode (code);
   if (u != null && userDao.isTmpUser (u))
   {
      userDao.registerTmpUser (u);

      // update cache entries
      Cache cache = cacheManager.getCache("user");
      if (cache != null)
      {
         synchronized (cache)
         {
            if (cache.get(u.getUUID()) != null)
            {
               cache.put(u.getUUID(), u);
            }
         }
      }

      cache = cacheManager.getCache("userByName");
      if (cache != null)
      {
         synchronized (cache)
         {
            if (cache.get(u.getUsername()) != null)
            {
               cache.put(u.getUsername(), u);
            }
         }
      }
   }
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:35,代碼來源:UserService.java

示例7: findInCaches

import org.springframework.cache.Cache; //導入方法依賴的package包/類
private Cache.ValueWrapper findInCaches(CacheOperationContext context, Object key) {
	for (Cache cache : context.getCaches()) {
		Cache.ValueWrapper wrapper = cache.get(key);
		if (wrapper != null) {
			return wrapper;
		}
	}
	return null;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:CacheAspectSupport.java

示例8: getHuaweiAK

import org.springframework.cache.Cache; //導入方法依賴的package包/類
/** 查詢huawei accessToken */
public AccessToken getHuaweiAK()
{
    Cache redisCache1101 = commonCacheManager.getCache("redisCache1101");
    @SuppressWarnings("unchecked")
    RedisTemplate<String, AccessToken> template = (RedisTemplate<String, AccessToken>)redisCache1101.getNativeCache();
    Set<String> keys = template.keys(CacheKeyPrefixConst.HW_ACCESS_TOKEN);

    if (null == keys || keys.isEmpty())
    {
        return null;
    }

    return redisCache1101.get(keys.iterator().next(), AccessToken.class);
}
 
開發者ID:marlonwang,項目名稱:raven,代碼行數:16,代碼來源:CacheService.java

示例9: removeProduct

import org.springframework.cache.Cache; //導入方法依賴的package包/類
/**
 * Updates caches after a product deletion.
 *
 * @param retObject object returned by the annotated method.
 */
@AfterReturning(
      pointcut = "@annotation(fr.gael.dhus.spring.cache.RemoveProduct)",
      returning = "retObject")
public void removeProduct(Object retObject)
{
   if (retObject != null && retObject instanceof Product)
   {
      Product p = (Product) retObject;

      // remove the given product from cache
      Cache cache = getCacheManager().getCache(PRODUCT_CACHE_NAME);
      synchronized (cache)
      {
         cache.evict(p.getId());
         cache.evict(p.getUuid());
      }

      // clear 'indexes' cache of the given product
      cache = getCacheManager().getCache(INDEXES_CACHE_NAME);
      cache.evict(p.getId());

      // decrement global 'product_count' and clear others key
      cache = getCacheManager().getCache(PRODUCT_COUNT_CACHE_NAME);
      synchronized (cache)
      {
         // save old value of all processed products
         Integer oldValue = cache.get(PRODUCT_COUNT_TOTAL_KEY, Integer.class);

         // clear cache
         cache.clear();

         // update value for all processed products if necessary
         if (oldValue != null)
         {
            cache.putIfAbsent(PRODUCT_COUNT_TOTAL_KEY, (oldValue - 1));
         }
      }

      // clear 'products' cache
      getCacheManager().getCache(PRODUCTS_CACHE_NAME).clear();
   }
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:48,代碼來源:CacheAspectDefinition.java

示例10: getCachedCustomerById

import org.springframework.cache.Cache; //導入方法依賴的package包/類
private Customer getCachedCustomerById(Cache cache, long id) {

        Cache.ValueWrapper valueWrapper = cache.get(id);

        if (valueWrapper == null) {
            return null;
        }

        return (Customer) valueWrapper.get();
    }
 
開發者ID:fdlessard,項目名稱:SpringBootLogExecutionTime,代碼行數:11,代碼來源:CacheableCustomerServiceImpl.java

示例11: getFromCache

import org.springframework.cache.Cache; //導入方法依賴的package包/類
/**
 * 從指定的緩存中獲取緩存數據
 *
 * @param cache Cache
 * @param key   Cache key
 * @return Cache value
 */
protected Object getFromCache(Cache cache, String key) {
    final Cache.ValueWrapper valueWrapper = cache.get(key);
    return valueWrapper == null ? null : valueWrapper.get();
}
 
開發者ID:monkeyk,項目名稱:oauth2-shiro-redis,代碼行數:12,代碼來源:AbstractCacheSupport.java

示例12: getFromCache

import org.springframework.cache.Cache; //導入方法依賴的package包/類
/**
 * 獲取緩存內容
 * @param cache
 * @param key
 * @return
 */
protected Object getFromCache(Cache cache, String key) {
    final Cache.ValueWrapper valueWrapper = cache.get(key);
    return null == valueWrapper ? null : valueWrapper.get();
}
 
開發者ID:cwenao,項目名稱:springboot_cwenao,代碼行數:11,代碼來源:AbstractCacheSupport.java


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