@CacheEntriesEvicted public void evicted(CacheEntriesEvictedEvent<Key<String>, ?> event) { if (!event.isPre()) { Cache<SessionAccessMetaDataKey, SessionAccessMetaData> cache = this.accessMetaDataCache.getAdvancedCache().withFlags(Flag.SKIP_LISTENER_NOTIFICATION); for (Key<String> key : event.getEntries().keySet()) { // Workaround for ISPN-8324 if (key instanceof SessionCreationMetaDataKey) { cache.evict(new SessionAccessMetaDataKey(key.getValue())); } } } } }
@CacheEntriesEvicted public void evicted(CacheEntriesEvictedEvent<Key<String>, ?> event) { if (!event.isPre()) { Set<SessionAttributeNamesKey> keys = new HashSet<>(); for (Key<String> key : event.getEntries().keySet()) { // Workaround for ISPN-8324 if (key instanceof SessionCreationMetaDataKey) { keys.add(new SessionAttributeNamesKey(key.getValue())); } } if (!keys.isEmpty()) { Cache<SessionAttributeKey, V> cache = this.attributeCache.getAdvancedCache().withFlags(Flag.SKIP_LISTENER_NOTIFICATION); for (Map.Entry<SessionAttributeNamesKey, Map<String, UUID>> entry : this.namesCache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_CACHE_LOAD, Flag.ZERO_LOCK_ACQUISITION_TIMEOUT, Flag.FAIL_SILENTLY).getAll(keys).entrySet()) { Map<String, UUID> names = entry.getValue(); if (names != null) { String sessionId = entry.getKey().getValue(); for (UUID attributeId : names.values()) { cache.evict(new SessionAttributeKey(sessionId, attributeId)); } } this.namesCache.getAdvancedCache().withFlags(Flag.SKIP_LISTENER_NOTIFICATION).evict(entry.getKey()); } } } } }
@CacheEntriesEvicted public void evicted(CacheEntriesEvictedEvent<Key<String>, ?> event) { if (!event.isPre()) { Cache<SessionAttributesKey, V> cache = this.cache.getAdvancedCache().withFlags(Flag.SKIP_LISTENER_NOTIFICATION); for (Key<String> key : event.getEntries().keySet()) { // Workaround for ISPN-8324 if (key instanceof SessionCreationMetaDataKey) { cache.evict(new SessionAttributesKey(key.getValue())); } } } } }
@CacheEntryPassivated public void passivated(CacheEntryPassivatedEvent<BeanGroupKey<I>, BeanGroupEntry<I, T>> event) { if (event.isPre()) { BeanGroupEntry<I, T> entry = event.getValue(); try (BeanGroup<I, T> group = new InfinispanBeanGroup<>(event.getKey().getId(), entry, this.context, Mutator.PASSIVE, this)) { for (I beanId : group.getBeans()) { BeanKey<I> beanKey = new InfinispanBeanKey<>(beanId); BeanEntry<I> beanEntry = this.beanCache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).get(beanKey); if ((beanEntry != null) && this.beanFilter.test(new AbstractMap.SimpleImmutableEntry<>(beanKey, beanEntry))) { InfinispanEjbLogger.ROOT_LOGGER.tracef("Passivating bean %s", beanKey); this.passiveCount.incrementAndGet(); group.prePassivate(beanId, this.passivationListener); // Cascade evict to bean entry this.beanCache.evict(beanKey); } } } catch (Exception e) { InfinispanEjbLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e); } } }
@Override public Void invoke(Cache<String, Map<Object, Object>> cache) { cache.evict(sessionId); return null; } };
@Autowired private CacheManager cacheManager; public void addReceipt(ReceiptObject receiptObject) throws Exception { feedbackDao.insertReceipt(receiptObject); Cache cache = cacheManager.getCache("assignedFeedbacks"); for (Object receiptId: receiptObject.getResolverIds()) { cache.evict(receiptId); } }
public class MakeAllCarsRedService{ @Autowired CacheManager cm; ... public void makeAllCarsRed(){ Cache cache = cm.getCache("cacheName"); //remove from cache cache.evict(key) //or, if neddec add to cache put(key, entity); ... } }
@Override public void evictCachedClientTemplateById(String id) { logger.tracev("Evicting client template {0}", id); cache.evict(id); }
protected final Future<Void> evictWithFuture(final Object key) { return fork(() -> { cache.evict(key); return null; }); }
public void testEvictNonExistantEntry() { String key = "key"; String value = "some-value"; cache.put(key, value); cache.evict(key); assertEquals(1, evictionListener.evictedEntries.size()); // Make sure if we evict again that it doesn't increase count cache.evict(key); // TODO: this seems like a bug, but many tests rely on this - maybe change later assertEquals(2, evictionListener.evictedEntries.size()); }
@Override public void remove(PersistentSession sessionInfo) { cache.remove( createSessionKey(sessionInfo.getId()) ); cache.evict( createSessionKey(sessionInfo.getId()) ); }
public void testLocksOnEvictNonexistent() throws Exception { LockTestData tl = lockTestData; Cache<String, String> cache = tl.cache; TransactionManager tm = tl.tm; assert !cache.containsKey("k") : "Should not exist"; tm.begin(); cache.evict("k"); assertNotLocked("k"); tm.commit(); assert !cache.containsKey("k") : "Should not exist"; assertNoLocks(); }
public void testRestoreAtomicMap(Method m) { cacheManager.defineConfiguration(m.getName(), configureCacheLoader(null, false).build()); Cache<String, Object> cache = cacheManager.getCache(m.getName()); AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, m.getName()); map.put("a", "b"); //evict from memory cache.evict(m.getName()); // now re-retrieve the map assertEquals("b", AtomicMapLookup.getAtomicMap(cache, m.getName()).get("a")); }
@Override public void call() { cache.put("k1", "v1"); cache.evict("k1"); assertEquals("cache size must be 0", 0, cache.getAdvancedCache().getDataContainer().size()); } });
public void testClear() { assertNotInCacheAndStore("k1", "k2", "k3"); cache.put("k1", "v1"); cache.put("k2", "v2"); cache.evict("k2"); assertInCacheNotInStore("k1", "v1"); assertInStoreNotInCache("k2", "v2"); cache.clear(); assertEquals(0, cache.size()); } }
public void testEvictInBatch() throws Exception { cache().put("myKey", "myValue"); cache().getAdvancedCache().startBatch(); //this should execute non-transactionally despite the batch transaction and should not fail as in https://issues.jboss.org/browse/ISPN-2845 cache().evict("myKey"); cache().getAdvancedCache().endBatch(true); assertFalse(cache().containsKey("myKey")); } }