当前位置: 首页>>代码示例>>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;未经允许,请勿转载。