@Override protected Cache getMissingCache(String name) { CacheManager cacheManager = getCacheManager(); Assert.state(cacheManager != null, "No CacheManager set"); // Check the JCache cache again (in case the cache was added at runtime) javax.cache.Cache<Object, Object> jcache = cacheManager.getCache(name); if (jcache != null) { return new JCacheCache(jcache, isAllowNullValues()); } return null; }
@Override protected JCacheCache getCache() { return getCache(true); }
@Override protected void addNativeCache(String cacheName) { cacheManagerMock.addCache(cacheName); }
@Before public void setupOnce() { cacheManagerMock = new CacheManagerMock(); cacheManagerMock.addCache(CACHE_NAME); cacheManager = new JCacheCacheManager(cacheManagerMock.getCacheManager()); cacheManager.setTransactionAware(false); cacheManager.afterPropertiesSet(); transactionalCacheManager = new JCacheCacheManager(cacheManagerMock.getCacheManager()); transactionalCacheManager.setTransactionAware(true); transactionalCacheManager.afterPropertiesSet(); }
@Override @Nullable public ValueWrapper putIfAbsent(Object key, @Nullable Object value) { boolean set = this.cache.putIfAbsent(key, toStoreValue(value)); return (set ? null : get(key)); }
@Override public void afterPropertiesSet() { if (getCacheManager() == null) { setCacheManager(Caching.getCachingProvider().getCacheManager()); } super.afterPropertiesSet(); }
@Override public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) { if (!(context instanceof CacheInvocationContext<?>)) { throw new IllegalStateException("Unexpected context " + context); } CacheInvocationContext<?> cacheInvocationContext = (CacheInvocationContext<?>) context; javax.cache.Cache<Object, Object> cache = this.target.resolveCache(cacheInvocationContext); if (cache == null) { throw new IllegalStateException("Could not resolve cache for " + context + " using " + this.target); } return Collections.singleton(new JCacheCache(cache)); }
@Override @Bean public org.springframework.cache.CacheManager cacheManager() { return new JCacheCacheManager(jCacheManager()); }
@Before public void setup() { this.cacheManager = getCachingProvider().getCacheManager(); this.cacheManager.createCache(CACHE_NAME, new MutableConfiguration<>()); this.cacheManager.createCache(CACHE_NAME_NO_NULL, new MutableConfiguration<>()); this.nativeCache = this.cacheManager.getCache(CACHE_NAME); this.cache = new JCacheCache(this.nativeCache); Cache<Object, Object> nativeCacheNoNull = this.cacheManager.getCache(CACHE_NAME_NO_NULL); this.cacheNoNull = new JCacheCache(nativeCacheNoNull, false); }
@Override public void put(Object key, @Nullable Object value) { this.cache.put(key, toStoreValue(value)); }
@Override @Nullable public <T> T get(Object key, Callable<T> valueLoader) { try { return this.cache.invoke(key, new ValueLoaderEntryProcessor<T>(), valueLoader); } catch (EntryProcessorException ex) { throw new ValueRetrievalException(key, valueLoader, ex.getCause()); } }
@Override protected void removeNativeCache(String cacheName) { cacheManagerMock.removeCache(cacheName); }
@Override protected ConfigurableApplicationContext getApplicationContext() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.getBeanFactory().registerSingleton("cachingProvider", getCachingProvider()); context.register(EnableCachingConfig.class); context.refresh(); jCacheManager = context.getBean("jCacheManager", CacheManager.class); return context; }
@Override protected Collection<Cache> loadCaches() { CacheManager cacheManager = getCacheManager(); Assert.state(cacheManager != null, "No CacheManager set"); Collection<Cache> caches = new LinkedHashSet<>(); for (String cacheName : cacheManager.getCacheNames()) { javax.cache.Cache<Object, Object> jcache = cacheManager.getCache(cacheName); caches.add(new JCacheCache(jcache, isAllowNullValues())); } return caches; }
@Override @Nullable public ValueWrapper putIfAbsent(Object key, @Nullable Object value) { boolean set = this.cache.putIfAbsent(key, toStoreValue(value)); return (set ? null : get(key)); }
@Override public void afterPropertiesSet() { if (getCacheManager() == null) { setCacheManager(Caching.getCachingProvider().getCacheManager()); } super.afterPropertiesSet(); }
@Override public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) { if (!(context instanceof CacheInvocationContext<?>)) { throw new IllegalStateException("Unexpected context " + context); } CacheInvocationContext<?> cacheInvocationContext = (CacheInvocationContext<?>) context; javax.cache.Cache<Object, Object> cache = this.target.resolveCache(cacheInvocationContext); if (cache == null) { throw new IllegalStateException("Could not resolve cache for " + context + " using " + this.target); } return Collections.singleton(new JCacheCache(cache)); }
@Override public void put(Object key, @Nullable Object value) { this.cache.put(key, toStoreValue(value)); }
@Override protected Cache getMissingCache(String name) { CacheManager cacheManager = getCacheManager(); Assert.state(cacheManager != null, "No CacheManager set"); // Check the JCache cache again (in case the cache was added at runtime) javax.cache.Cache<Object, Object> jcache = cacheManager.getCache(name); if (jcache != null) { return new JCacheCache(jcache, isAllowNullValues()); } return null; }
@Override protected Collection<Cache> loadCaches() { CacheManager cacheManager = getCacheManager(); Assert.state(cacheManager != null, "No CacheManager set"); Collection<Cache> caches = new LinkedHashSet<>(); for (String cacheName : cacheManager.getCacheNames()) { javax.cache.Cache<Object, Object> jcache = cacheManager.getCache(cacheName); caches.add(new JCacheCache(jcache, isAllowNullValues())); } return caches; }