本文整理匯總了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();
}