/** * Returns the cache with the specified {@code name}. If the cache instance does not yet exist, it will be lazily * created, retained for further access, and then returned. * * @param name the name of the cache to acquire. * @return the cache with the specified {@code name}. * @throws IllegalArgumentException if the {@code name} argument is {@code null} or does not contain text. * @throws CacheException if there is a problem lazily creating a {@code Cache} instance. */ public <K, V> Cache<K, V> getCache(String name) throws IllegalArgumentException, CacheException { if (!StringUtils.hasText(name)) { throw new IllegalArgumentException("Cache name cannot be null or empty."); } Cache cache; cache = caches.get(name); if (cache == null) { cache = createCache(name); Cache existing = caches.putIfAbsent(name, cache); if (existing != null) { cache = existing; } } //noinspection unchecked return cache; }
@Override public void destroy() throws Exception { super.destroy(); try { ((JedisConnectionFactory) redisTemplate.getConnectionFactory()).destroy(); } catch (Throwable e) { } } }
/** * Returns the cache with the specified {@code name}. If the cache instance does not yet exist, it will be lazily * created, retained for further access, and then returned. * * @param name the name of the cache to acquire. * @return the cache with the specified {@code name}. * @throws IllegalArgumentException if the {@code name} argument is {@code null} or does not contain text. * @throws CacheException if there is a problem lazily creating a {@code Cache} instance. */ public <K, V> Cache<K, V> getCache(String name) throws IllegalArgumentException, CacheException { if (!StringUtils.hasText(name)) { throw new IllegalArgumentException("Cache name cannot be null or empty."); } Cache cache; cache = caches.get(name); if (cache == null) { cache = createCache(name); Cache existing = caches.putIfAbsent(name, cache); if (existing != null) { cache = existing; } } //noinspection unchecked return cache; }