本文整理汇总了Java中org.springframework.cache.Cache.evict方法的典型用法代码示例。如果您正苦于以下问题:Java Cache.evict方法的具体用法?Java Cache.evict怎么用?Java Cache.evict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.cache.Cache
的用法示例。
在下文中一共展示了Cache.evict方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performCacheEvict
import org.springframework.cache.Cache; //导入方法依赖的package包/类
private void performCacheEvict(CacheOperationContext context, CacheEvictOperation operation, Object result) {
Object key = null;
for (Cache cache : context.getCaches()) {
if (operation.isCacheWide()) {
logInvalidating(context, operation, null);
cache.clear();
}
else {
if (key == null) {
key = context.generateKey(result);
}
logInvalidating(context, operation, key);
cache.evict(key);
}
}
}
示例2: doEvict
import org.springframework.cache.Cache; //导入方法依赖的package包/类
protected void doEvict(String cacheName, String key) {
FluuzCache cache = cacheMap.get(cacheName);
if (cache != null) {
Cache proxy = cache.getProxy();
proxy.evict(key);
log.debug("evicted key '{}' from cache {}", key, cacheName);
}
}
示例3: 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();
}
}
示例4: evictFromCache
import org.springframework.cache.Cache; //导入方法依赖的package包/类
/**
* 清除缓存中具体的 缓存数据
*
* @param cache Cache
* @param key Cache key
* @return True is evict successful
*/
protected boolean evictFromCache(Cache cache, Object key) {
if (key == null) {
LOG.debug("Ignore evict from cache[{}], because key is null", cache);
return false;
}
cache.evict(key);
LOG.debug("Evict key[{}] from cache[{}]", key, cache);
return true;
}
示例5: evictFromCache
import org.springframework.cache.Cache; //导入方法依赖的package包/类
/**
* 删除缓存数据
* @param cache
* @param key
* @return
*/
protected boolean evictFromCache(Cache cache,Object key){
if(null == key){
return false;
}
cache.evict(key);
return true;
}
示例6: 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();
}
}