org.infinispan.Cache.evict()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中org.infinispan.Cache.evict()方法的一些代码示例,展示了Cache.evict()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.evict()方法的具体详情如下:
包路径:org.infinispan.Cache
类名称:Cache
方法名:evict

Cache.evict介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

@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()));
        }
      }
    }
  }
}

代码示例来源:origin: wildfly/wildfly

@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());
        }
      }
    }
  }
}

代码示例来源:origin: wildfly/wildfly

@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()));
        }
      }
    }
  }
}

代码示例来源:origin: wildfly/wildfly

@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);
    }
  }
}

代码示例来源:origin: org.jboss.as/jboss-as-clustering-web-infinispan

@Override
  public Void invoke(Cache<String, Map<Object, Object>> cache) {
    cache.evict(sessionId);
    return null;
  }
};

代码示例来源:origin: stackoverflow.com

@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);
  }
}

代码示例来源:origin: stackoverflow.com

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);
...
}
}

代码示例来源:origin: org.keycloak/keycloak-invalidation-cache-infinispan

@Override
public void evictCachedClientTemplateById(String id) {
  logger.tracev("Evicting client template {0}", id);
  cache.evict(id);
}

代码示例来源:origin: org.infinispan/infinispan-core

@Override
protected void writeInitialData(final Cache<Object, Object> c) {
 super.writeInitialData(c);
 c.evict(A_B_NAME);
 c.evict(A_B_AGE);
 c.evict(A_C_NAME);
 c.evict(A_C_AGE);
 c.evict(A_D_NAME);
 c.evict(A_D_AGE);
}

代码示例来源:origin: org.infinispan/infinispan-core

public static void writeInitialData(final Cache<Object, Object> c) {
 c.put(A_B_NAME, JOE);
 c.put(A_B_AGE, TWENTY);
 c.put(A_C_NAME, BOB);
 c.put(A_C_AGE, FORTY);
 c.evict(A_B_NAME);
 c.evict(A_B_AGE);
 c.evict(A_C_NAME);
 c.evict(A_C_AGE);
 c.evict(A_D_NAME);
 c.evict(A_D_AGE);
}

代码示例来源:origin: org.infinispan/infinispan-core

protected final Future<Void> evictWithFuture(final Object key) {
 return fork(() -> {
   cache.evict(key);
   return null;
 });
}

代码示例来源:origin: org.infinispan/infinispan-core

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());
}

代码示例来源:origin: org.kie/drools-infinispan-persistence

@Override
public void remove(PersistentSession sessionInfo) {
  cache.remove( createSessionKey(sessionInfo.getId()) );
  cache.evict( createSessionKey(sessionInfo.getId()) );
}

代码示例来源:origin: org.infinispan/infinispan-core

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();
}

代码示例来源:origin: org.infinispan/infinispan-core

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"));
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testEvictAndRemove() throws PersistenceException {
 assertNotInCacheAndStore("k1", "k2");
 cache.put("k1", "v1");
 cache.put("k2", "v2", lifespan, MILLISECONDS);
 cache.evict("k1");
 cache.evict("k2");
 assertEquals("v1", cache.remove("k1"));
 assertEquals("v2", cache.remove("k2"));
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testPassivationOnEvict(Method m) throws Exception {
 assertPassivationCount(0);
 cache.put(k(m), v(m));
 cache.put(k(m, 2), v(m, 2));
 cache.evict(k(m));
 assertPassivationCount(1);
 cache.evict(k(m, 2));
 assertPassivationCount(2);
 cache.evict("not_existing_key");
 assertPassivationCount(2);
}

代码示例来源:origin: org.infinispan/infinispan-core

@Override
  public void call() {
   cache.put("k1", "v1");
   cache.evict("k1");
   assertEquals("cache size must be 0", 0, cache.getAdvancedCache().getDataContainer().size());
  }
});

代码示例来源:origin: org.infinispan/infinispan-core

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());
  }
}

代码示例来源:origin: org.infinispan/infinispan-core

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"));
  }
}

相关文章