List of usage examples for org.springframework.cache Cache getName
String getName();
From source file:am.ik.categolj2.infra.cache.LoggingCacheAdaptor.java
public LoggingCacheAdaptor(Cache targetCache) { this.targetCache = targetCache; this.name = targetCache.getName(); }
From source file:grails.plugin.cache.ehcache.GrailsEhcacheCacheManager.java
protected void addCache(Cache cache) { cacheMap.put(cache.getName(), cache); cacheNames.add(cache.getName()); }
From source file:net.eusashead.spring.gaecache.GaeCacheTest.java
@Test public void testCacheName() throws Exception { String name = "test"; Cache cache = new GaeCache(name); Assert.assertEquals(name, cache.getName()); }
From source file:com.couchbase.client.spring.cache.CouchbaseCacheManagerTests.java
/** * Test cache creation with custom TTL values. */// w w w . java 2 s . c o m @Test public void testCacheInitWithTtl() { HashMap<String, Bucket> instances = new HashMap<String, Bucket>(); instances.put("cache1", client); instances.put("cache2", client); HashMap<String, Integer> ttlConfiguration = new HashMap<String, Integer>(); ttlConfiguration.put("cache1", 100); ttlConfiguration.put("cache2", 200); CouchbaseCacheManager manager = new CouchbaseCacheManager(instances, ttlConfiguration); manager.afterPropertiesSet(); assertEquals(instances, manager.getClients()); Cache cache1 = manager.getCache("cache1"); Cache cache2 = manager.getCache("cache2"); assertNotNull(cache1); assertNotNull(cache2); assertEquals(cache1.getClass(), CouchbaseCache.class); assertEquals(cache2.getClass(), CouchbaseCache.class); assertEquals(cache1.getName(), "cache1"); assertEquals(cache2.getName(), "cache2"); assertEquals(((CouchbaseCache) cache1).getTtl(), 100); assertEquals(((CouchbaseCache) cache2).getTtl(), 200); assertEquals(((CouchbaseCache) cache1).getNativeCache(), client); assertEquals(((CouchbaseCache) cache2).getNativeCache(), client); }
From source file:org.infinispan.spring.spi.SpringEmbeddedCacheManagerTest.java
/** * Test method for {@link org.infinispan.spring.spi.SpringEmbeddedCacheManager#getCache(String)}. * @throws IOException //from www .java 2s . co m */ @Test public final void getCacheShouldReturnTheCacheHavingTheProvidedName() throws IOException { final EmbeddedCacheManager nativeCacheManager = new DefaultCacheManager( SpringEmbeddedCacheManagerTest.class.getResourceAsStream(NAMED_ASYNC_CACHE_CONFIG_LOCATION)); final SpringEmbeddedCacheManager objectUnderTest = new SpringEmbeddedCacheManager(nativeCacheManager); final Cache<Object, Object> cacheExpectedToHaveTheProvidedName = objectUnderTest .getCache(CACHE_NAME_FROM_CONFIGURATION_FILE); assertEquals("getCache(" + CACHE_NAME_FROM_CONFIGURATION_FILE + ") should have returned the cache having the provided name. However, the cache returned has a different name.", CACHE_NAME_FROM_CONFIGURATION_FILE, cacheExpectedToHaveTheProvidedName.getName()); nativeCacheManager.stop(); }
From source file:org.infinispan.spring.spi.SpringRemoteCacheManagerTest.java
/** * Test method for {@link org.infinispan.spring.spi.SpringRemoteCacheManager#getCache(java.lang.String)}. *//*from w w w . j av a 2 s .co m*/ @Test public final void springRemoteCacheManagerShouldProperlyCreateCache() { final String cacheName = "spring.remote.cache.manager.Test"; final RemoteCacheManager nativeCacheManager = new RemoteCacheManager(true); final SpringRemoteCacheManager objectUnderTest = new SpringRemoteCacheManager(nativeCacheManager); final Cache<Object, Object> defaultCache = objectUnderTest.getCache(cacheName); assertNotNull( "getCache(" + cacheName + ") should have returned a default cache. However, it returned null.", defaultCache); assertEquals( "getCache(" + cacheName + ") should have returned a cache name \"" + cacheName + "\". However, the returned cache has a different name.", cacheName, defaultCache.getName()); nativeCacheManager.stop(); }
From source file:grails.plugin.cache.web.filter.PageFragmentCachingFilter.java
protected void update(Collection<Cache> caches, PageInfo pageInfo, CacheStatus cacheStatus, String key) { ValueWrapper element = cacheStatus == null ? null : cacheStatus.valueWrapper; Object maxAge = pageInfo.getCacheDirectives().get("max-age"); int timeToLive = (maxAge instanceof Integer) ? ((Integer) maxAge) : (int) pageInfo.getTimeToLiveSeconds(); for (Cache cache : caches) { log.debug("Response ok. Adding to cache {} with key {} and ttl {}", new Object[] { cache.getName(), key, getTimeToLive(element) }); put(cache, key, pageInfo, timeToLive); }//w w w. j a v a2s . c om }
From source file:grails.plugin.cache.web.filter.PageFragmentCachingFilter.java
protected PageInfo buildNewPageInfo(HttpServletRequest request, HttpServletResponse response, FilterChain chain, CacheStatus cacheStatus, Map<String, Collection<CacheOperationContext>> operationsByType) throws Exception { Timer timer = new Timer(getCachedUri(request)); timer.start();// w w w. j a va 2s.co m String key = calculateKey(request); PageInfo pageInfo; try { // Page is not cached - build the response, cache it, and send to client pageInfo = buildPage(request, response, chain); if (pageInfo.isOk()) { Object noCache = pageInfo.getCacheDirectives().get("no-cache"); if (noCache instanceof Boolean && ((Boolean) noCache)) { log.debug("Response ok but Cache-Control: no-cache is present, not caching"); releaseCacheLocks(operationsByType, key); } else { Collection<Cache> caches = new ArrayList<Cache>(); for (CacheOperationContext operationContext : operationsByType.get(UPDATE)) { for (Cache cache : operationContext.getCaches()) { caches.add(cache); } } update(caches, pageInfo, cacheStatus, key); } } else { for (CacheOperationContext operationContext : operationsByType.get(UPDATE)) { for (Cache cache : operationContext.getCaches()) { log.debug("Response not ok ({}). Putting null into cache {} with key {}", new Object[] { pageInfo.getStatusCode(), cache.getName(), key }); } } releaseCacheLocks(operationsByType, key); } } catch (Exception e) { if ("net.sf.ehcache.constructs.blocking.LockTimeoutException".equals(e.getClass().getName())) { //do not release the lock, because you never acquired it throw e; } // Must unlock the cache if the above fails. Will be logged at Filter releaseCacheLocks(operationsByType, key); throw e; } timer.stop(false); response.addHeader(X_CACHED, String.valueOf(false)); return pageInfo; }
From source file:org.redis.cache.RedisCacheManager.java
/** * Returns a new {@link Collection} of {@link Cache} from the given caches * collection and adds the configured {@link Cache}s of they are not already * present./* w w w. j a v a 2s .co m*/ * * @param caches * must not be {@literal null} * @return */ protected Collection<? extends Cache> addConfiguredCachesIfNecessary(Collection<? extends Cache> caches) { Assert.notNull(caches, "Caches must not be null!"); Collection<Cache> result = new ArrayList<Cache>(caches); for (String cacheName : getCacheNames()) { boolean configuredCacheAlreadyPresent = false; for (Cache cache : caches) { if (cache.getName().equals(cacheName)) { configuredCacheAlreadyPresent = true; break; } } if (!configuredCacheAlreadyPresent) { result.add(getCache(cacheName)); } } return result; }
From source file:org.springframework.cache.interceptor.CacheAspectSupport.java
@Nullable private Cache.ValueWrapper findInCaches(CacheOperationContext context, Object key) { for (Cache cache : context.getCaches()) { Cache.ValueWrapper wrapper = doGet(cache, key); if (wrapper != null) { if (logger.isTraceEnabled()) { logger.trace("Cache entry for key '" + key + "' found in cache '" + cache.getName() + "'"); }/*w ww. j a v a2 s . c o m*/ return wrapper; } } return null; }