Java Code Examples for javax.cache.Cache#removeAll()
The following examples show how to use
javax.cache.Cache#removeAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheExpiryTest.java From cache2k with Apache License 2.0 | 6 votes |
@Test public void testCacheStatisticsRemoveAllNoneExpired() throws Exception { ExpiryPolicy policy = new CreatedExpiryPolicy(Duration.ETERNAL); expiryPolicyServer.setExpiryPolicy(policy); MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>(); config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicyClient)) .setStatisticsEnabled(true); Cache<Integer, Integer> cache = getCacheManager().createCache(getTestCacheName(), config); for (int i = 0; i < 100; i++) { cache.put(i, i+100); } cache.removeAll(); assertEquals(100L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts")); assertEquals(100L, lookupManagementAttribute(cache, CacheStatistics, "CacheRemovals")); }
Example 2
Source File: CacheExpiryTest.java From cache2k with Apache License 2.0 | 6 votes |
@Test public void testCacheStatisticsRemoveAll() throws Exception { long _EXPIRY_MILLIS = 3; //cannot be zero or will not be added to the cache ExpiryPolicy policy = new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, _EXPIRY_MILLIS)); expiryPolicyServer.setExpiryPolicy(policy); MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>(); config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicyClient)).setStatisticsEnabled(true); Cache<Integer, Integer> cache = getCacheManager().createCache(getTestCacheName(), config); for (int i = 0; i < 100; i++) { cache.put(i, i+100); } //should work with all implementations Thread.sleep(_EXPIRY_MILLIS); cache.removeAll(); assertEquals(100L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts")); //Removals does not count expired entries assertEquals(0L, lookupManagementAttribute(cache, CacheStatistics, "CacheRemovals")); }
Example 3
Source File: JCacheOAuthDataProvider.java From cxf with Apache License 2.0 | 6 votes |
protected static <K, V extends ServerAccessToken> List<V> getTokens(Cache<K, V> cache, Client client, UserSubject sub) { final Set<K> toRemove = new HashSet<>(); final List<V> tokens = new ArrayList<>(); for (Iterator<Cache.Entry<K, V>> it = cache.iterator(); it.hasNext();) { Cache.Entry<K, V> entry = it.next(); V token = entry.getValue(); if (isExpired(token)) { toRemove.add(entry.getKey()); } else if (isTokenMatched(token, client, sub)) { tokens.add(token); } } cache.removeAll(toRemove); return tokens; }
Example 4
Source File: EntitlementBaseCache.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Remove everything in the cache. */ public void clear() { Cache<K, V> cache = getEntitlementCache(); if (cache != null) { try { cache.removeAll(); if (log.isDebugEnabled()) { String tenantDomain = CarbonContext .getThreadLocalCarbonContext().getTenantDomain(); log.debug("Cache : " + Entitlement_CACHE_NAME + " is cleared " + "in tenant domain : " + tenantDomain); } } catch (Exception e) { //TODO - Handle the IdentityCacheKey exception in cluster env. } } }
Example 5
Source File: BaseCache.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Remove everything in the cache. */ public void clear() { if (!isEnabled()) { return; } try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext .getThreadLocalCarbonContext(); carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID); carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); Cache<K, V> cache = getBaseCache(); if (cache != null) { cache.removeAll(); } } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 6
Source File: BaseCache.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Remove everything in the cache. */ public void clear() { if (!isEnabled()) { return; } try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext .getThreadLocalCarbonContext(); carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID); carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); Cache<K, V> cache = getBaseCache(); if (cache != null) { cache.removeAll(); } } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 7
Source File: EntitlementBaseCache.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Remove everything in the cache. */ public void clear() { Cache<K, V> cache = getEntitlementCache(); if (cache != null) { try { cache.removeAll(); if (log.isDebugEnabled()) { String tenantDomain = CarbonContext .getThreadLocalCarbonContext().getTenantDomain(); log.debug("Cache : " + Entitlement_CACHE_NAME + " is cleared " + "in tenant domain : " + tenantDomain); } } catch (Exception e) { //TODO - Handle the IdentityCacheKey exception in cluster env. } } }
Example 8
Source File: AuthorizationCache.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Clears the cache by tenantId to facilitate the cache clearance when role * authorization is cleared. * * @param tenantId */ public void clearCacheByTenant(int tenantId) { Cache<AuthorizationKey, AuthorizeCacheEntry> cache = this.getAuthorizationCache(); if (!isCacheNull(cache)) { cache.removeAll(); } }
Example 9
Source File: CacheInvalidationServiceImpl.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Override public void invalidateResourceCache(String apiContext, String apiVersion, ResourceCacheInvalidationDto[] uriTemplates) { boolean isTenantFlowStarted = false; int tenantDomainIndex = apiContext.indexOf("/t/"); String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; if (tenantDomainIndex != -1) { String temp = apiContext.substring(tenantDomainIndex + 3, apiContext.length()); tenantDomain = temp.substring(0, temp.indexOf('/')); } try { isTenantFlowStarted = startTenantFlow(tenantDomain); Cache cache = CacheProvider.getResourceCache(); if (apiContext.contains(APIConstants.POLICY_CACHE_CONTEXT)) { if (log.isDebugEnabled()) { log.debug("Cleaning cache for policy update for tenant " + tenantDomain); } cache.removeAll(); } else { String apiCacheKey = APIUtil.getAPIInfoDTOCacheKey(apiContext, apiVersion); if (cache.containsKey(apiCacheKey)) { cache.remove(apiCacheKey); } for (ResourceCacheInvalidationDto uriTemplate : uriTemplates) { String resourceVerbCacheKey = APIUtil.getResourceInfoDTOCacheKey(apiContext, apiVersion, uriTemplate.getResourceURLContext(), uriTemplate.getHttpVerb()); if (cache.containsKey(resourceVerbCacheKey)) { cache.remove(resourceVerbCacheKey); } } } } finally { if (isTenantFlowStarted) { endTenantFlow(); } } }
Example 10
Source File: JCacheTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testRemoveAll() throws Exception { RedisProcess runner = new RedisRunner() .nosave() .randomDir() .port(6311) .run(); URL configUrl = getClass().getResource("redisson-jcache.json"); Config cfg = Config.fromJSON(configUrl); Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg); Cache<String, String> cache = Caching.getCachingProvider().getCacheManager() .createCache("test", config); cache.put("1", "2"); cache.put("3", "4"); cache.put("4", "4"); cache.put("5", "5"); Set<? extends String> keys = new HashSet<String>(Arrays.asList("1", "3", "4", "5")); cache.removeAll(keys); assertThat(cache.containsKey("1")).isFalse(); assertThat(cache.containsKey("3")).isFalse(); assertThat(cache.containsKey("4")).isFalse(); assertThat(cache.containsKey("5")).isFalse(); cache.close(); runner.stop(); }
Example 11
Source File: PEPProxyCache.java From carbon-identity with Apache License 2.0 | 5 votes |
void clear() { if (simpleCache != null) { simpleCache = new SimpleCache<>(simpleCache.maxEntries); } else if (isCarbonCache) { Cache<IdentityCacheKey, IdentityCacheEntry> carbonCache = getCommonCache(); if (carbonCache != null) { carbonCache.removeAll(); } } }
Example 12
Source File: OpenIDBaseCache.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Remove everything in the cache. */ public void clear() { Cache<K, V> cache = getOpenIDCache(); if (cache != null) { cache.removeAll(); } }
Example 13
Source File: PolicyCacheManagerImpl.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
@Override public void updateAllPolicies(List<Policy> policies) { Cache<Integer, List<Policy>> lCache = getPolicyListCache(); lCache.removeAll(); lCache.put(1, policies); }
Example 14
Source File: BaseCache.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * Remove everything in the cache. */ public void clear() { if (!isEnabled()) { return; } Cache<K, V> cache = getBaseCache(); if (cache != null) { cache.removeAll(); } }
Example 15
Source File: PEPProxyCache.java From micro-integrator with Apache License 2.0 | 5 votes |
void clear() { if (simpleCache != null) { simpleCache = new SimpleCache<>(simpleCache.maxEntries); } else if (isCarbonCache) { Cache<IdentityCacheKey, IdentityCacheEntry> carbonCache = getCommonCache(); if (carbonCache != null) { carbonCache.removeAll(); } } }
Example 16
Source File: AuthorizationCache.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Clears the cache. */ public void clearCache() { Cache<AuthorizationKey, AuthorizeCacheEntry> cache = this.getAuthorizationCache(); // check for null if (isCacheNull(cache)) { return; } cache.removeAll(); }
Example 17
Source File: PolicyCacheManagerImpl.java From carbon-device-mgt with Apache License 2.0 | 4 votes |
@Override public void removeAllPolicies() { Cache<Integer, List<Policy>> lCache = getPolicyListCache(); lCache.removeAll(); }
Example 18
Source File: RealmCache.java From micro-integrator with Apache License 2.0 | 4 votes |
/** * Remove everything in the cache. */ public void clear() { Cache<RealmCacheKey, RealmCacheEntry> cache = getRealmCache(); cache.removeAll(); }
Example 19
Source File: UserRolesCache.java From micro-integrator with Apache License 2.0 | 4 votes |
public void clearCacheByTenant(int tenantId) { Cache<UserRolesCacheKey, UserRolesCacheEntry> cache = this.getUserRolesCache(); cache.removeAll(); }