org.springframework.cache.Cache.evict()

Here are the examples of the java api org.springframework.cache.Cache.evict() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

67 Examples 7

19 View Source File : CachedDAOImpl.java
License : GNU General Public License v2.0
Project Creator : taktik

public void evictFromCache(T enreplacedy) {
    cache.evict(getFullId(keyManager.getKey(enreplacedy)));
    cache.evict(getFullId(ALL_ENreplacedIES_CACHE_KEY));
}

19 View Source File : CachedDAOImpl.java
License : GNU General Public License v2.0
Project Creator : taktik

public void evictFromCache(String id) {
    cache.evict(id);
}

19 View Source File : CachedDAOImpl.java
License : GNU General Public License v2.0
Project Creator : taktik

public void evictFromCache(String groupId, String id) {
    cache.evict(((CouchDbICureConnector) this.db).getCouchDbICureConnector(groupId).getUuid() + ":" + id);
}

19 View Source File : SafeCache.java
License : GNU General Public License v2.0
Project Creator : taktik

public synchronized void evict(K key) {
    cache.evict(key);
}

19 View Source File : PostCachingTests.java
License : GNU General Public License v3.0
Project Creator : mintster

@After
public void evictCaches() {
    postCache.evict("posts");
    pagedPostsCache.evict("pagedPosts");
}

19 View Source File : OAuth2Service.java
License : GNU General Public License v3.0
Project Creator : microacup

// code 只能使用一次
public void evict(String code) {
    codeCache.evict(code);
}

19 View Source File : PaymentApplicationService.java
License : Apache License 2.0
Project Creator : fenixsoft

/**
 * 取消支付
 * 立即触发解冻定时器,释放库存和资金
 */
public void cancelPayment(String payId) {
    // 释放冻结的库存
    paymentService.cancel(payId);
    // 支付成功的清除缓存
    settlementCache.evict(payId);
}

19 View Source File : PaymentApplicationService.java
License : Apache License 2.0
Project Creator : fenixsoft

/**
 * 完成支付
 * 立即取消解冻定时器,执行扣减库存和资金
 */
public void accomplishPayment(Integer accountId, String payId) {
    // 订单从冻结状态变为派送状态,扣减库存
    double price = paymentService.accomplish(payId);
    // 扣减货款
    walletService.decrease(accountId, price);
    // 支付成功的清除缓存
    settlementCache.evict(payId);
}

19 View Source File : InMemoryClusterStore.java
License : Apache License 2.0
Project Creator : alibaba

@Override
public void removeAgent(String agentId) {
    cache.evict(agentId);
}

18 View Source File : AbstractCacheInvoker.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Execute {@link Cache#evict(Object)} on the specified {@link Cache} and
 * invoke the error handler if an exception occurs.
 */
protected void doEvict(Cache cache, Object key) {
    try {
        cache.evict(key);
    } catch (RuntimeException ex) {
        getErrorHandler().handleCacheEvictError(ex, cache, key);
    }
}

18 View Source File : CachedDAOImpl.java
License : GNU General Public License v2.0
Project Creator : taktik

@Override
protected <K extends Collection<T>> K save(Boolean newEnreplacedy, K enreplacedies) {
    try {
        enreplacedies = super.save(newEnreplacedy, enreplacedies);
    } catch (UpdateConflictException | BulkUpdateConflictException e) {
        for (T enreplacedy : enreplacedies) {
            cache.evict(getFullId(keyManager.getKey(enreplacedy)));
        }
        cache.evict(getFullId(ALL_ENreplacedIES_CACHE_KEY));
        throw e;
    }
    for (T enreplacedy : enreplacedies) {
        putInCache(keyManager.getKey(enreplacedy), enreplacedy);
    }
    cache.evict(getFullId(ALL_ENreplacedIES_CACHE_KEY));
    return enreplacedies;
}

18 View Source File : CachedDAOImpl.java
License : GNU General Public License v2.0
Project Creator : taktik

@Override
protected T save(Boolean newEnreplacedy, T enreplacedy) {
    try {
        enreplacedy = super.save(newEnreplacedy, enreplacedy);
    } catch (UpdateConflictException e) {
        cache.evict(getFullId(keyManager.getKey(enreplacedy)));
        cache.evict(getFullId(ALL_ENreplacedIES_CACHE_KEY));
        throw e;
    }
    putInCache(keyManager.getKey(enreplacedy), enreplacedy);
    cache.evict(getFullId(ALL_ENreplacedIES_CACHE_KEY));
    return enreplacedy;
}

18 View Source File : GitHubTests.java
License : GNU General Public License v3.0
Project Creator : mintster

@After
public void tearDown() {
    githubCache.evict("githubStats");
}

18 View Source File : SpringCacheCaptchaCache.java
License : GNU Lesser General Public License v3.0
Project Creator : lets-mica

@Override
public String getAndRemove(String cacheName, String uuid) {
    String value = captchaCache.get(uuid, String.clreplaced);
    if (value != null) {
        captchaCache.evict(uuid);
    }
    return value;
}

18 View Source File : AbstractCacheInvoker.java
License : Apache License 2.0
Project Creator : langtianya

/**
 * Execute {@link Cache#evict(Object)} on the specified {@link Cache} and
 * invoke the error handler if an exception occurs.
 */
protected void doEvict(Cache cache, Object key) {
    try {
        cache.evict(key);
    } catch (RuntimeException e) {
        getErrorHandler().handleCacheEvictError(e, cache, key);
    }
}

18 View Source File : AuthTokenServiceImpl.java
License : MIT License
Project Creator : jonathanlermitage

/**
 * Evict given token existence from {@link Globals.CacheNames#CACHE_TOKEN_EXISTENCE} cache via code, not via annotation: this method
 * can be safely called from another method of this clreplaced (when called from an other method of this clreplaced, annotation based cache eviction
 * would not work). See <a href="https://spring.io/blog/2012/05/23/transactions-caching-and-aop-understanding-proxy-usage-in-spring">understanding proxy
 * usage in Spring</a> and
 * <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#cache">Cache Abstraction</a> for details on
 * proxy clreplacedes. TL;DR: <cite>In proxy mode (the default), only external method calls coming in through the proxy are intercepted.
 * This means that self-invocation (in effect, a method within the target object that calls another method of the target object) does
 * not lead to actual caching at runtime even if the invoked method is marked with <code>@Cacheable</code>. Consider using the aspectj
 * mode in this case. Also, the proxy must be fully initialized to provide the expected behavior, so you should not rely on this feature
 * in your initialization code (that is, <code>@PostConstruct</code>).</cite>
 */
private void evictTokenExistenceCache(long id) {
    Cache cache = cm.getCache(Globals.CacheNames.CACHE_TOKEN_EXISTENCE);
    if (cache != null) {
        cache.evict(id);
    }
}

18 View Source File : ShiroSpringCache.java
License : Apache License 2.0
Project Creator : freezek

@Override
public V remove(K key) throws CacheException {
    if (logger.isTraceEnabled()) {
        logger.trace("Removing object from cache [" + this.cache.getName() + "] for key [" + key + "]key type:" + key.getClreplaced());
    }
    V previous = get(key);
    cache.evict(key);
    return previous;
}

18 View Source File : ShiroSpringCache.java
License : Apache License 2.0
Project Creator : fengbindev

@Override
public V remove(K key) throws CacheException {
    V v = get(key);
    // 干掉这个名字为key的缓存
    cache.evict(key);
    return v;
}

18 View Source File : AbstractCacheSupport.java
License : MIT License
Project Creator : cwenao

/**
 * 删除缓存数据
 * @param cache
 * @param key
 * @return
 */
protected boolean evictFromCache(Cache cache, Object key) {
    if (null == key) {
        return false;
    }
    cache.evict(key);
    return true;
}

18 View Source File : MultiL2Cache.java
License : Apache License 2.0
Project Creator : choerodon

@Override
public void evict(Object key) {
    l2Cache.evict(key);
}

18 View Source File : MultiL1Cache.java
License : Apache License 2.0
Project Creator : choerodon

@Override
public void evict(Object key) {
    l1Cache.evict(key);
}

18 View Source File : MultiAllCache.java
License : Apache License 2.0
Project Creator : choerodon

@Override
public void evict(Object key) {
    l2Cache.evict(key);
    l1Cache.evict(key);
}

17 View Source File : CacheManagerUtil.java
License : GNU Affero General Public License v3.0
Project Creator : zycSummer

public void evictCache(String cacheName, String key) {
    Cache cache = cacheManager.getCache(cacheName);
    if (cache != null) {
        cache.evict(key);
    }
}

17 View Source File : SysLoginService.java
License : Apache License 2.0
Project Creator : yang-cruise

private LoginUser getLoginUser(LoginPrincipal principal, String credentials) throws NotBindWechatException {
    UsernamePreplacedwordAuthenticationToken authenticationToken = new UsernamePreplacedwordAuthenticationToken(principal, credentials);
    String securityVerifyCacheKey = this.getSecurityVerifyCacheKey();
    Authentication authentication;
    try {
        authentication = authenticationManager.authenticate(authenticationToken);
    } catch (BadCredentialsException e) {
        addBadCredentialsCountBySecurity(securityVerifyCacheKey);
        throw new BusinessException(getPreplacedwordErrorMsg(principal));
    } catch (NotBindWechatException e) {
        throw e;
    } catch (Exception e) {
        addBadCredentialsCountBySecurity(securityVerifyCacheKey);
        log.info("登录失败,principal = [{}], msg = [{}]", principal.getPrincipal(), e.getMessage());
        throw new BusinessException(e.getMessage());
    }
    // 清除缓存
    securityCache.evict(securityVerifyCacheKey);
    accountCache.evict(principal.getPrincipal());
    LoginUser loginUser = (LoginUser) authentication.getPrincipal();
    SecurityContextHolder.getContext().setAuthentication(authentication);
    return loginUser;
}

17 View Source File : CacheManagerEndpoint.java
License : Apache License 2.0
Project Creator : SpringCloud

@DeleteMapping("/{cacheManager}/{cache}/{key}")
public Object evictCacheKey(@PathVariable("cacheManager") String cacheManager, @PathVariable("cache") String cache, @PathVariable("cache") String key) {
    applicationContext.getBeansOfType(CacheManager.clreplaced).entrySet().stream().filter(en -> en.getKey().equals(cacheManager)).forEach(en -> {
        Cache c = en.getValue().getCache(cache);
        if (c != null) {
            c.evict(key);
        }
    });
    return null;
}

17 View Source File : AbstractCacheInvoker.java
License : Apache License 2.0
Project Creator : SourceHot

/**
 * Execute {@link Cache#evict(Object)}/{@link Cache#evictIfPresent(Object)} on the
 * specified {@link Cache} and invoke the error handler if an exception occurs.
 */
protected void doEvict(Cache cache, Object key, boolean immediate) {
    try {
        if (immediate) {
            cache.evictIfPresent(key);
        } else {
            cache.evict(key);
        }
    } catch (RuntimeException ex) {
        getErrorHandler().handleCacheEvictError(ex, cache, key);
    }
}

17 View Source File : TranslateCaffeineManager.java
License : Apache License 2.0
Project Creator : sagframe

/**
 * 这里cacheKey
 */
@Override
public void clear(String cacheName, String cacheType) {
    if (cacheManager == null) {
        return;
    }
    synchronized (cacheName) {
        Cache cache = cacheManager.getCache(cacheName);
        // 缓存没有配置,自动创建缓存不建议使用
        if (cache != null) {
            if (StringUtil.isBlank(cacheType)) {
                cache.clear();
            } else {
                cache.evict(cacheType);
            }
        }
    }
}

17 View Source File : UrlInfoServiceImpl.java
License : MIT License
Project Creator : liuweijw

@Override
public UrlInfoBean findFromCacheByUuid(String uuid) {
    log.info("从缓存查询微信UrlInfo[uuid]:" + uuid);
    Cache cache = cacheManager.getCache(WECHAT_URL_INFO);
    Optional<UrlInfoBean> optional = Optional.ofNullable(cache.get(uuid, UrlInfoBean.clreplaced));
    if (optional.isPresent()) {
        log.info("从缓存查询微信UrlInfo[uuid]:" + uuid + "查询成功");
        cache.evict(uuid);
        return optional.get();
    }
    log.error("从缓存查询微信UrlInfo[uuid]:" + uuid + "未查询到");
    UrlInfo dbUserinfo = findByUuid(uuid);
    if (null == dbUserinfo) {
        log.error("从db查询微信UrlInfo[uuid]:" + uuid + "未查询到");
        return new UrlInfoBean();
    }
    log.info("从db查询微信UrlInfo[uuid]:" + uuid + "查询成功");
    return new UrlInfoBean(dbUserinfo.getUuid(), dbUserinfo.getUrl());
}

17 View Source File : JbCacheManagerImpl.java
License : GNU General Public License v3.0
Project Creator : JuniperBot

@Override
public <K> void evict(String cacheName, K key) {
    Cache cache = getCache(cacheName);
    if (cache != null) {
        cache.evict(key);
    }
}

17 View Source File : LockManagerImpl.java
License : Apache License 2.0
Project Creator : Haulmont

@Override
public void expireLocks() {
    if (cacheOperations.isIterableCache(locks)) {
        Collection<LockKey> keys = cacheOperations.getKeys(locks);
        for (LockKey key : keys) {
            LockInfo lockInfo = locks.get(key, LockInfo.clreplaced);
            if (lockInfo != null) {
                LockDescriptor ld = getConfig().get(key.name);
                if (ld == null) {
                    log.debug("Lock {}/{} configuration not found, remove it", key.name, key.id);
                    locks.evict(key);
                } else {
                    Integer timeoutSec = ld.getTimeoutSec();
                    if (timeoutSec != null && timeoutSec > 0) {
                        Date since = lockInfo.getSince();
                        if (since.getTime() + timeoutSec * 1000 < timeSource.currentTimestamp().getTime()) {
                            log.debug("Lock {}/{} expired", key.name, key.id);
                            locks.evict(key);
                        }
                    }
                }
            }
        }
    } else {
        log.debug("Expiring locks operation is unsupported by cache provider");
    }
}

17 View Source File : AuthServiceImpl.java
License : Apache License 2.0
Project Creator : gy2006

@Override
public void logout() {
    User user = sessionManager.remove();
    onlineUsersCache.evict(user.getEmail());
    refreshTokenCache.evict(user.getEmail());
}

17 View Source File : PaymentApplicationService.java
License : Apache License 2.0
Project Creator : fenixsoft

/**
 * 完成支付
 * 立即取消解冻定时器,执行扣减库存和资金
 */
public void accomplishPayment(Integer accountId, String payId) {
    // 订单从冻结状态变为派送状态,扣减库存
    double price = paymentService.accomplish(payId);
    try {
        // 扣减货款
        walletService.decrease(accountId, price);
    } catch (Throwable e) {
        // 扣款失败,将已支付的记录回滚恢复库存
        paymentService.rollbackSettlement(Payment.State.PAYED, payId);
        throw e;
    }
    // 支付成功的清除缓存
    settlementCache.evict(payId);
}

17 View Source File : DockerCacheInvalidator.java
License : Apache License 2.0
Project Creator : codeabovelab

private Consumer<DockerLogEvent> makeInvalidator(Cache cache) {
    return (e) -> {
        ContainerBase container = e.getContainer();
        String name = container.getName();
        String id = container.getId();
        if (name != null && id != null) {
            cache.evict(name);
            cache.evict(id);
            // docker also can return containers by its 12 symbols id
            cache.evict(id.substring(0, 12));
        }
    };
}

17 View Source File : InvalidCacheEventConsumer.java
License : Apache License 2.0
Project Creator : alibaba

private void invalidateSpringCache(List<String> keys) {
    if (cacheManager == null)
        return;
    keys.forEach(key -> {
        String[] parts = key.split(":", 2);
        try {
            Cache cache = cacheManager.getCache(parts[0]);
            if (cache != null) {
                cache.evict(parts[1]);
            }
        } catch (Exception ignore) {
        }
    });
}

16 View Source File : SysLoginController.java
License : GNU Affero General Public License v3.0
Project Creator : zycSummer

/**
 * 退出
 */
@PostMapping(value = "/sys/logout")
public ResponseEnreplacedy<String> logout() {
    Cache cache = cacheManager.getCache("yami_sys_user");
    if (cache != null) {
        cache.evict(SecurityUtils.getSysUser().getUsername());
    }
    SecurityContextHolder.clearContext();
    return ResponseEnreplacedy.ok().build();
}

16 View Source File : TransactionAwareCacheDecoratorTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void evictNonTransactional() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);
    Object key = new Object();
    cache.put(key, "123");
    cache.evict(key);
    replacedertNull(target.get(key));
}

16 View Source File : CaffeineCacheManagerTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testStaticMode() {
    CaffeineCacheManager cm = new CaffeineCacheManager("c1", "c2");
    Cache cache1 = cm.getCache("c1");
    replacedertTrue(cache1 instanceof CaffeineCache);
    Cache cache1again = cm.getCache("c1");
    replacedertSame(cache1again, cache1);
    Cache cache2 = cm.getCache("c2");
    replacedertTrue(cache2 instanceof CaffeineCache);
    Cache cache2again = cm.getCache("c2");
    replacedertSame(cache2again, cache2);
    Cache cache3 = cm.getCache("c3");
    replacedertNull(cache3);
    cache1.put("key1", "value1");
    replacedertEquals("value1", cache1.get("key1").get());
    cache1.put("key2", 2);
    replacedertEquals(2, cache1.get("key2").get());
    cache1.put("key3", null);
    replacedertNull(cache1.get("key3").get());
    cache1.evict("key3");
    replacedertNull(cache1.get("key3"));
    cm.setAllowNullValues(false);
    Cache cache1x = cm.getCache("c1");
    replacedertTrue(cache1x instanceof CaffeineCache);
    replacedertTrue(cache1x != cache1);
    Cache cache2x = cm.getCache("c2");
    replacedertTrue(cache2x instanceof CaffeineCache);
    replacedertTrue(cache2x != cache2);
    Cache cache3x = cm.getCache("c3");
    replacedertNull(cache3x);
    cache1x.put("key1", "value1");
    replacedertEquals("value1", cache1x.get("key1").get());
    cache1x.put("key2", 2);
    replacedertEquals(2, cache1x.get("key2").get());
    cm.setAllowNullValues(true);
    Cache cache1y = cm.getCache("c1");
    cache1y.put("key3", null);
    replacedertNull(cache1y.get("key3").get());
    cache1y.evict("key3");
    replacedertNull(cache1y.get("key3"));
}

16 View Source File : ConcurrentMapCacheManagerTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testStaticMode() {
    ConcurrentMapCacheManager cm = new ConcurrentMapCacheManager("c1", "c2");
    Cache cache1 = cm.getCache("c1");
    replacedertTrue(cache1 instanceof ConcurrentMapCache);
    Cache cache1again = cm.getCache("c1");
    replacedertSame(cache1again, cache1);
    Cache cache2 = cm.getCache("c2");
    replacedertTrue(cache2 instanceof ConcurrentMapCache);
    Cache cache2again = cm.getCache("c2");
    replacedertSame(cache2again, cache2);
    Cache cache3 = cm.getCache("c3");
    replacedertNull(cache3);
    cache1.put("key1", "value1");
    replacedertEquals("value1", cache1.get("key1").get());
    cache1.put("key2", 2);
    replacedertEquals(2, cache1.get("key2").get());
    cache1.put("key3", null);
    replacedertNull(cache1.get("key3").get());
    cache1.evict("key3");
    replacedertNull(cache1.get("key3"));
    cm.setAllowNullValues(false);
    Cache cache1x = cm.getCache("c1");
    replacedertTrue(cache1x instanceof ConcurrentMapCache);
    replacedertTrue(cache1x != cache1);
    Cache cache2x = cm.getCache("c2");
    replacedertTrue(cache2x instanceof ConcurrentMapCache);
    replacedertTrue(cache2x != cache2);
    Cache cache3x = cm.getCache("c3");
    replacedertNull(cache3x);
    cache1x.put("key1", "value1");
    replacedertEquals("value1", cache1x.get("key1").get());
    cache1x.put("key2", 2);
    replacedertEquals(2, cache1x.get("key2").get());
    cm.setAllowNullValues(true);
    Cache cache1y = cm.getCache("c1");
    cache1y.put("key3", null);
    replacedertNull(cache1y.get("key3").get());
    cache1y.evict("key3");
    replacedertNull(cache1y.get("key3"));
}

16 View Source File : TransactionAwareCacheDecoratorTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void evictNonTransactional() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);
    Object key = new Object();
    cache.put(key, "123");
    cache.evict(key);
    replacedertThat(target.get(key)).isNull();
}

16 View Source File : CaffeineCacheManagerTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void testStaticMode() {
    CaffeineCacheManager cm = new CaffeineCacheManager("c1", "c2");
    Cache cache1 = cm.getCache("c1");
    boolean condition3 = cache1 instanceof CaffeineCache;
    replacedertThat(condition3).isTrue();
    Cache cache1again = cm.getCache("c1");
    replacedertThat(cache1).isSameAs(cache1again);
    Cache cache2 = cm.getCache("c2");
    boolean condition2 = cache2 instanceof CaffeineCache;
    replacedertThat(condition2).isTrue();
    Cache cache2again = cm.getCache("c2");
    replacedertThat(cache2).isSameAs(cache2again);
    Cache cache3 = cm.getCache("c3");
    replacedertThat(cache3).isNull();
    cache1.put("key1", "value1");
    replacedertThat(cache1.get("key1").get()).isEqualTo("value1");
    cache1.put("key2", 2);
    replacedertThat(cache1.get("key2").get()).isEqualTo(2);
    cache1.put("key3", null);
    replacedertThat(cache1.get("key3").get()).isNull();
    cache1.evict("key3");
    replacedertThat(cache1.get("key3")).isNull();
    cm.setAllowNullValues(false);
    Cache cache1x = cm.getCache("c1");
    boolean condition1 = cache1x instanceof CaffeineCache;
    replacedertThat(condition1).isTrue();
    replacedertThat(cache1x != cache1).isTrue();
    Cache cache2x = cm.getCache("c2");
    boolean condition = cache2x instanceof CaffeineCache;
    replacedertThat(condition).isTrue();
    replacedertThat(cache2x != cache2).isTrue();
    Cache cache3x = cm.getCache("c3");
    replacedertThat(cache3x).isNull();
    cache1x.put("key1", "value1");
    replacedertThat(cache1x.get("key1").get()).isEqualTo("value1");
    cache1x.put("key2", 2);
    replacedertThat(cache1x.get("key2").get()).isEqualTo(2);
    cm.setAllowNullValues(true);
    Cache cache1y = cm.getCache("c1");
    cache1y.put("key3", null);
    replacedertThat(cache1y.get("key3").get()).isNull();
    cache1y.evict("key3");
    replacedertThat(cache1y.get("key3")).isNull();
}

16 View Source File : ConcurrentMapCacheManagerTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void testStaticMode() {
    ConcurrentMapCacheManager cm = new ConcurrentMapCacheManager("c1", "c2");
    Cache cache1 = cm.getCache("c1");
    boolean condition3 = cache1 instanceof ConcurrentMapCache;
    replacedertThat(condition3).isTrue();
    Cache cache1again = cm.getCache("c1");
    replacedertThat(cache1).isSameAs(cache1again);
    Cache cache2 = cm.getCache("c2");
    boolean condition2 = cache2 instanceof ConcurrentMapCache;
    replacedertThat(condition2).isTrue();
    Cache cache2again = cm.getCache("c2");
    replacedertThat(cache2).isSameAs(cache2again);
    Cache cache3 = cm.getCache("c3");
    replacedertThat(cache3).isNull();
    cache1.put("key1", "value1");
    replacedertThat(cache1.get("key1").get()).isEqualTo("value1");
    cache1.put("key2", 2);
    replacedertThat(cache1.get("key2").get()).isEqualTo(2);
    cache1.put("key3", null);
    replacedertThat(cache1.get("key3").get()).isNull();
    cache1.evict("key3");
    replacedertThat(cache1.get("key3")).isNull();
    cm.setAllowNullValues(false);
    Cache cache1x = cm.getCache("c1");
    boolean condition1 = cache1x instanceof ConcurrentMapCache;
    replacedertThat(condition1).isTrue();
    replacedertThat(cache1x != cache1).isTrue();
    Cache cache2x = cm.getCache("c2");
    boolean condition = cache2x instanceof ConcurrentMapCache;
    replacedertThat(condition).isTrue();
    replacedertThat(cache2x != cache2).isTrue();
    Cache cache3x = cm.getCache("c3");
    replacedertThat(cache3x).isNull();
    cache1x.put("key1", "value1");
    replacedertThat(cache1x.get("key1").get()).isEqualTo("value1");
    cache1x.put("key2", 2);
    replacedertThat(cache1x.get("key2").get()).isEqualTo(2);
    cm.setAllowNullValues(true);
    Cache cache1y = cm.getCache("c1");
    cache1y.put("key3", null);
    replacedertThat(cache1y.get("key3").get()).isNull();
    cache1y.evict("key3");
    replacedertThat(cache1y.get("key3")).isNull();
}

16 View Source File : TransactionAwareCacheDecoratorTests.java
License : Apache License 2.0
Project Creator : langtianya

@Test
public void evictTransactional() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);
    Object key = new Object();
    cache.put(key, "123");
    TransactionStatus status = txManager.getTransaction(new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED));
    cache.evict(key);
    replacedertEquals("123", target.get(key, String.clreplaced));
    txManager.commit(status);
    replacedertNull(target.get(key));
}

16 View Source File : GuavaCacheManagerTests.java
License : Apache License 2.0
Project Creator : langtianya

@Test
public void testStaticMode() {
    GuavaCacheManager cm = new GuavaCacheManager("c1", "c2");
    Cache cache1 = cm.getCache("c1");
    replacedertTrue(cache1 instanceof GuavaCache);
    Cache cache1again = cm.getCache("c1");
    replacedertSame(cache1again, cache1);
    Cache cache2 = cm.getCache("c2");
    replacedertTrue(cache2 instanceof GuavaCache);
    Cache cache2again = cm.getCache("c2");
    replacedertSame(cache2again, cache2);
    Cache cache3 = cm.getCache("c3");
    replacedertNull(cache3);
    cache1.put("key1", "value1");
    replacedertEquals("value1", cache1.get("key1").get());
    cache1.put("key2", 2);
    replacedertEquals(2, cache1.get("key2").get());
    cache1.put("key3", null);
    replacedertNull(cache1.get("key3").get());
    cache1.evict("key3");
    replacedertNull(cache1.get("key3"));
    cm.setAllowNullValues(false);
    Cache cache1x = cm.getCache("c1");
    replacedertTrue(cache1x instanceof GuavaCache);
    replacedertTrue(cache1x != cache1);
    Cache cache2x = cm.getCache("c2");
    replacedertTrue(cache2x instanceof GuavaCache);
    replacedertTrue(cache2x != cache2);
    Cache cache3x = cm.getCache("c3");
    replacedertNull(cache3x);
    cache1x.put("key1", "value1");
    replacedertEquals("value1", cache1x.get("key1").get());
    cache1x.put("key2", 2);
    replacedertEquals(2, cache1x.get("key2").get());
    try {
        cache1x.put("key3", null);
        fail("Should have thrown NullPointerException");
    } catch (NullPointerException ex) {
    // expected
    }
    cm.setAllowNullValues(true);
    Cache cache1y = cm.getCache("c1");
    cache1y.put("key3", null);
    replacedertNull(cache1y.get("key3").get());
    cache1y.evict("key3");
    replacedertNull(cache1y.get("key3"));
}

16 View Source File : GuavaCacheManagerTests.java
License : Apache License 2.0
Project Creator : langtianya

@Test
public void testDynamicMode() {
    CacheManager cm = new GuavaCacheManager();
    Cache cache1 = cm.getCache("c1");
    replacedertTrue(cache1 instanceof GuavaCache);
    Cache cache1again = cm.getCache("c1");
    replacedertSame(cache1again, cache1);
    Cache cache2 = cm.getCache("c2");
    replacedertTrue(cache2 instanceof GuavaCache);
    Cache cache2again = cm.getCache("c2");
    replacedertSame(cache2again, cache2);
    Cache cache3 = cm.getCache("c3");
    replacedertTrue(cache3 instanceof GuavaCache);
    Cache cache3again = cm.getCache("c3");
    replacedertSame(cache3again, cache3);
    cache1.put("key1", "value1");
    replacedertEquals("value1", cache1.get("key1").get());
    cache1.put("key2", 2);
    replacedertEquals(2, cache1.get("key2").get());
    cache1.put("key3", null);
    replacedertNull(cache1.get("key3").get());
    cache1.evict("key3");
    replacedertNull(cache1.get("key3"));
}

16 View Source File : ConcurrentMapCacheManagerTests.java
License : Apache License 2.0
Project Creator : langtianya

@Test
public void testStaticMode() {
    ConcurrentMapCacheManager cm = new ConcurrentMapCacheManager("c1", "c2");
    Cache cache1 = cm.getCache("c1");
    replacedertTrue(cache1 instanceof ConcurrentMapCache);
    Cache cache1again = cm.getCache("c1");
    replacedertSame(cache1again, cache1);
    Cache cache2 = cm.getCache("c2");
    replacedertTrue(cache2 instanceof ConcurrentMapCache);
    Cache cache2again = cm.getCache("c2");
    replacedertSame(cache2again, cache2);
    Cache cache3 = cm.getCache("c3");
    replacedertNull(cache3);
    cache1.put("key1", "value1");
    replacedertEquals("value1", cache1.get("key1").get());
    cache1.put("key2", 2);
    replacedertEquals(2, cache1.get("key2").get());
    cache1.put("key3", null);
    replacedertNull(cache1.get("key3").get());
    cache1.evict("key3");
    replacedertNull(cache1.get("key3"));
    cm.setAllowNullValues(false);
    Cache cache1x = cm.getCache("c1");
    replacedertTrue(cache1x instanceof ConcurrentMapCache);
    replacedertTrue(cache1x != cache1);
    Cache cache2x = cm.getCache("c2");
    replacedertTrue(cache2x instanceof ConcurrentMapCache);
    replacedertTrue(cache2x != cache2);
    Cache cache3x = cm.getCache("c3");
    replacedertNull(cache3x);
    cache1x.put("key1", "value1");
    replacedertEquals("value1", cache1x.get("key1").get());
    cache1x.put("key2", 2);
    replacedertEquals(2, cache1x.get("key2").get());
    try {
        cache1x.put("key3", null);
        fail("Should have thrown NullPointerException");
    } catch (NullPointerException ex) {
    // expected
    }
    cm.setAllowNullValues(true);
    Cache cache1y = cm.getCache("c1");
    cache1y.put("key3", null);
    replacedertNull(cache1y.get("key3").get());
    cache1y.evict("key3");
    replacedertNull(cache1y.get("key3"));
}

16 View Source File : EhCachePluginImpl.java
License : Apache License 2.0
Project Creator : hiparker

@Override
public boolean delete(String cacheName, String key) {
    if (cacheManager == null) {
        return true;
    }
    boolean ret = false;
    try {
        Cache cache = cacheManager.getCache(cacheName);
        if (cache != null) {
            cache.evict(key);
            ret = true;
        }
    } catch (Exception e) {
        log.error(EhCacheMsg.EXCEPTION_DEL.getMessage() + ":{}", e.getMessage());
    }
    return ret;
}

15 View Source File : TransactionAwareCacheDecoratorTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void evictTransactional() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);
    Object key = new Object();
    cache.put(key, "123");
    TransactionStatus status = this.txManager.getTransaction(new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED));
    cache.evict(key);
    replacedertEquals("123", target.get(key, String.clreplaced));
    this.txManager.commit(status);
    replacedertNull(target.get(key));
}

15 View Source File : TransactionAwareCacheDecoratorTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void evictTransactional() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);
    Object key = new Object();
    cache.put(key, "123");
    txTemplate.executeWithoutResult(s -> {
        cache.evict(key);
        replacedertThat(target.get(key, String.clreplaced)).isEqualTo("123");
    });
    replacedertThat(target.get(key)).isNull();
}

15 View Source File : CaffeineCacheController.java
License : Apache License 2.0
Project Creator : ck-jesse

/**
 * 清除缓存
 */
@RequestMapping(value = "/evictCache")
public String evictCache(String cacheName, String key, String optType) {
    Cache cache = cacheManager.getCache(cacheName);
    if (null == cache) {
        return "fail cache is not exists: " + cacheName;
    }
    if (CacheConsts.CACHE_REFRESH.equals(optType)) {
        cache.evict(key);
    } else {
        cache.clear();
    }
    return "success";
}

14 View Source File : CaffeineCacheManagerTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testDynamicMode() {
    CacheManager cm = new CaffeineCacheManager();
    Cache cache1 = cm.getCache("c1");
    replacedertTrue(cache1 instanceof CaffeineCache);
    Cache cache1again = cm.getCache("c1");
    replacedertSame(cache1again, cache1);
    Cache cache2 = cm.getCache("c2");
    replacedertTrue(cache2 instanceof CaffeineCache);
    Cache cache2again = cm.getCache("c2");
    replacedertSame(cache2again, cache2);
    Cache cache3 = cm.getCache("c3");
    replacedertTrue(cache3 instanceof CaffeineCache);
    Cache cache3again = cm.getCache("c3");
    replacedertSame(cache3again, cache3);
    cache1.put("key1", "value1");
    replacedertEquals("value1", cache1.get("key1").get());
    cache1.put("key2", 2);
    replacedertEquals(2, cache1.get("key2").get());
    cache1.put("key3", null);
    replacedertNull(cache1.get("key3").get());
    cache1.evict("key3");
    replacedertNull(cache1.get("key3"));
}

See More Examples