本文整理汇总了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);
}
示例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));
}
示例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 ()));
}
}
}
示例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());
}
示例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();
}
}
示例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);
}
}
}
}
}
示例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;
}
示例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);
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}