@Test public void testResolveCache() throws Exception { expect(mockContext.getCacheName()).andReturn("name").times(2); replay(mockContext); Cache cache1 = cacheResolver.resolveCache(mockContext, Optional.<CacheConfig>absent()); Cache cache2 = cacheResolver.resolveCache(mockContext, Optional.<CacheConfig>absent()); assertTrue(cache1.equals(cache2)); }
@Override public Cache<GeneratedCacheKey, Optional<?>> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext, Optional<CacheConfig> cacheConfig) { final String cacheName = cacheInvocationContext.getCacheName(); Cache<GeneratedCacheKey, Optional<?>> cache = namespaces.get(cacheName); if (null == cache) { LOGGER.debug("Build new dao cache for name {}", cacheName); CacheBuilder<GeneratedCacheKey, Optional<?>> cacheBuilder = cacheBuilderProvider.get().name(cacheName); if (cacheConfig.isPresent()) { if (cacheConfig.get().size() > 0) { cacheBuilder.maximumSize(cacheConfig.get().size()); } if (cacheConfig.get().expiresAfterSeconds() > 0) { cacheBuilder.expireAfterWrite(cacheConfig.get().expiresAfterSeconds()); } } cache = cacheBuilder.build(); Cache<GeneratedCacheKey, Optional<?>> existingCache = namespaces.putIfAbsent(cacheName, cache); if (null != existingCache) { cache = existingCache; } } return cache; }
DefaultCacheResolver implements CacheResolver { @Override public Cache<GeneratedCacheKey, Optional<?>> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext, Optional<CacheConfig> cacheConfig) { final String cacheName = cacheInvocationContext.getCacheName(); Cache<GeneratedCacheKey, Optional<?>> cache = namespaces.get(cacheName); if (null == cache) { LOGGER.debug("Build new dao cache for name {}", cacheName); CacheBuilder<GeneratedCacheKey, Optional<?>> cacheBuilder = cacheBuilderProvider.get().name(cacheName); if (cacheConfig.isPresent()) { if (cacheConfig.get().size() > 0) { cacheBuilder.maximumSize(cacheConfig.get().size()); } if (cacheConfig.get().expiresAfterSeconds() > 0) { cacheBuilder.expireAfterWrite(cacheConfig.get().expiresAfterSeconds()); } } cache = cacheBuilder.build(); Cache<GeneratedCacheKey, Optional<?>> existingCache = namespaces.putIfAbsent(cacheName, cache); if (null != existingCache) { cache = existingCache; } } return cache; } }
DefaultCacheResolver implements CacheResolver { @Override public Cache<GeneratedCacheKey, Optional<?>> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext, Optional<CacheConfig> cacheConfig) { final String cacheName = cacheInvocationContext.getCacheName(); Cache<GeneratedCacheKey, Optional<?>> cache = namespaces.get(cacheName); if (null == cache) { LOGGER.debug("Build new dao cache for name {}", cacheName); CacheBuilder<GeneratedCacheKey, Optional<?>> cacheBuilder = cacheBuilderProvider.get().name(cacheName); if (cacheConfig.isPresent()) { if (cacheConfig.get().size() > 0) { cacheBuilder.maximumSize(cacheConfig.get().size()); } if (cacheConfig.get().expiresAfterSeconds() > 0) { cacheBuilder.expireAfterWrite(cacheConfig.get().expiresAfterSeconds()); } } cache = cacheBuilder.build(); Cache<GeneratedCacheKey, Optional<?>> existingCache = namespaces.putIfAbsent(cacheName, cache); if (null != existingCache) { cache = existingCache; } } return cache; } @Inject  DefaultCacheResolver(Provider<CacheBuilder> cacheBuilderProvider); }
DefaultCacheResolver implements CacheResolver { @Override public Cache<GeneratedCacheKey, Optional<?>> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext, Optional<CacheConfig> cacheConfig) { final String cacheName = cacheInvocationContext.getCacheName(); Cache<GeneratedCacheKey, Optional<?>> cache = namespaces.get(cacheName); if (null == cache) { LOGGER.debug("Build new dao cache for name {}", cacheName); CacheBuilder<GeneratedCacheKey, Optional<?>> cacheBuilder = cacheBuilderProvider.get().name(cacheName); if (cacheConfig.isPresent()) { if (cacheConfig.get().size() > 0) { cacheBuilder.maximumSize(cacheConfig.get().size()); } if (cacheConfig.get().expiresAfterSeconds() > 0) { cacheBuilder.expireAfterWrite(cacheConfig.get().expiresAfterSeconds()); } } cache = cacheBuilder.build(); Cache<GeneratedCacheKey, Optional<?>> existingCache = namespaces.putIfAbsent(cacheName, cache); if (null != existingCache) { cache = existingCache; } } return cache; } @Inject  DefaultCacheResolver(Provider<CacheBuilder> cacheBuilderProvider); @Override Cache<GeneratedCacheKey, Optional<?>> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext,
                                                            Optional<CacheConfig> cacheConfig); }
DefaultCacheResolver implements CacheResolver { @Override public Cache<GeneratedCacheKey, Optional<?>> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext, Optional<CacheConfig> cacheConfig) { final String cacheName = cacheInvocationContext.getCacheName(); Cache<GeneratedCacheKey, Optional<?>> cache = namespaces.get(cacheName); if (null == cache) { LOGGER.debug("Build new dao cache for name {}", cacheName); CacheBuilder<GeneratedCacheKey, Optional<?>> cacheBuilder = cacheBuilderProvider.get().name(cacheName); if (cacheConfig.isPresent()) { if (cacheConfig.get().size() > 0) { cacheBuilder.maximumSize(cacheConfig.get().size()); } if (cacheConfig.get().expiresAfterSeconds() > 0) { cacheBuilder.expireAfterWrite(cacheConfig.get().expiresAfterSeconds()); } } cache = cacheBuilder.build(); Cache<GeneratedCacheKey, Optional<?>> existingCache = namespaces.putIfAbsent(cacheName, cache); if (null != existingCache) { cache = existingCache; } } return cache; } @Inject  DefaultCacheResolver(Provider<CacheBuilder> cacheBuilderProvider); @Override Cache<GeneratedCacheKey, Optional<?>> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext,
                                                            Optional<CacheConfig> cacheConfig);  }