Java Code Examples for javax.cache.Cache#close()
The following examples show how to use
javax.cache.Cache#close() .
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: NotSerializableTest.java From commons-jcs with Apache License 2.0 | 6 votes |
@Test public void run() { final CachingProvider cachingProvider = Caching.getCachingProvider(); final CacheManager cacheManager = cachingProvider.getCacheManager(); cacheManager.createCache("default", new MutableConfiguration<String, NotSerializableAndImHappyWithIt>().setStoreByValue(false)); final Cache<String, NotSerializableAndImHappyWithIt> cache = cacheManager.getCache("default"); assertFalse(cache.containsKey("foo")); cache.put("foo", new NotSerializableAndImHappyWithIt("bar")); assertTrue(cache.containsKey("foo")); assertEquals("bar", cache.get("foo").name); cache.remove("foo"); assertFalse(cache.containsKey("foo")); cache.close(); cacheManager.close(); cachingProvider.close(); }
Example 2
Source File: JCacheTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testJson() throws InterruptedException, IllegalArgumentException, URISyntaxException, IOException { RedisProcess runner = new RedisRunner() .nosave() .randomDir() .port(6311) .run(); URL configUrl = getClass().getResource("redisson-jcache.json"); Config cfg = Config.fromJSON(configUrl); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JavaTimeModule()); cfg.setCodec(new TypedJsonJacksonCodec(String.class, LocalDateTime.class, objectMapper)); Configuration<String, LocalDateTime> config = RedissonConfiguration.fromConfig(cfg); Cache<String, LocalDateTime> cache = Caching.getCachingProvider().getCacheManager() .createCache("test", config); LocalDateTime t = LocalDateTime.now(); cache.put("1", t); Assert.assertEquals(t, cache.get("1")); cache.close(); runner.stop(); }
Example 3
Source File: JCacheTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testRx() 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); CacheRx<String, String> rx = cache.unwrap(CacheRx.class); rx.put("1", "2").blockingAwait(); assertThat(rx.get("1").blockingGet()).isEqualTo("2"); cache.close(); runner.stop(); }
Example 4
Source File: JCacheTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testAsync() 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); CacheAsync<String, String> async = cache.unwrap(CacheAsync.class); async.putAsync("1", "2").get(); assertThat(async.getAsync("1").get()).isEqualTo("2"); cache.close(); runner.stop(); }
Example 5
Source File: JCacheTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testClear() 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.clear(); assertThat(cache.get("1")).isNull(); cache.close(); runner.stop(); }
Example 6
Source File: JCacheManager.java From redisson with Apache License 2.0 | 6 votes |
@Override public void close() { if (isClosed()) { return; } synchronized (cacheProvider) { if (!isClosed()) { cacheProvider.close(uri, classLoader); for (Cache<?, ?> cache : caches.values()) { try { cache.close(); } catch (Exception e) { // skip } } if (redisson != null) { redisson.shutdown(); } closed = true; } } }
Example 7
Source File: JCSCachingManager.java From commons-jcs with Apache License 2.0 | 6 votes |
@Override public synchronized void close() { if (isClosed()) { return; } assertNotClosed(); for (final Cache<?, ?> c : caches.values()) { c.close(); } caches.clear(); closed = true; if (JCSCachingProvider.class.isInstance(provider)) { JCSCachingProvider.class.cast(provider).remove(this); } delegate.shutDown(); }
Example 8
Source File: JCSCachingManager.java From commons-jcs with Apache License 2.0 | 5 votes |
@Override public void destroyCache(final String cacheName) { assertNotClosed(); assertNotNull(cacheName, "cacheName"); final Cache<?, ?> cache = caches.remove(cacheName); if (cache != null && !cache.isClosed()) { cache.clear(); cache.close(); } }
Example 9
Source File: CacheManagerImpl.java From caffeine with Apache License 2.0 | 5 votes |
@Override public void destroyCache(String cacheName) { requireNotClosed(); Cache<?, ?> cache = caches.remove(cacheName); if (cache != null) { cache.close(); } }
Example 10
Source File: CacheManagerImpl.java From caffeine with Apache License 2.0 | 5 votes |
@Override public void close() { if (isClosed()) { return; } synchronized (this) { if (!isClosed()) { cacheProvider.close(uri, classLoaderReference.get()); for (Cache<?, ?> cache : caches.values()) { cache.close(); } closed = true; } } }
Example 11
Source File: JCacheTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testRedissonConfig() throws InterruptedException, IllegalArgumentException, URISyntaxException, IOException { 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"); Assert.assertEquals("2", cache.get("1")); cache.put("key", "value"); String result = cache.getAndRemove("key"); Assert.assertEquals("value", result); Assert.assertNull(cache.get("key")); cache.put("key", "value"); cache.remove("key"); Assert.assertNull(cache.get("key")); cache.close(); runner.stop(); }
Example 12
Source File: MangleICacheTest.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
@TimeStep(prob = 0.1) public void closeCache(ThreadState state) { int cacheNumber = state.randomInt(maxCaches); Cache cache = state.getCacheIfExists(cacheNumber); try { if (cache != null) { cache.close(); state.counter.cacheClose++; } } catch (CacheException | IllegalStateException e) { state.counter.cacheCloseException++; } }
Example 13
Source File: RepositoryCacheManager.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Override public void destroyCache(String cacheName) { requireNotClosed(); Cache<?, ?> cache = caches.remove(cacheName); if (cache != null) { cache.close(); } }
Example 14
Source File: CacheManagerTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test @Ignore("not yet") public void create_config_cache2k_types() { CachingProvider p = Caching.getCachingProvider(); CacheManager cm = p.getCacheManager(); ExtendedMutableConfiguration<String, BigDecimal> mc = new ExtendedMutableConfiguration<String, BigDecimal>(); mc.setCache2kConfiguration( new Cache2kBuilder<String, BigDecimal>(){} .toConfiguration() ); Cache<String, BigDecimal> c = cm.createCache("aCache", mc); assertEquals("aCache", c.getName()); assertEquals(String.class, c.getConfiguration(Configuration.class).getKeyType()); assertEquals(BigDecimal.class, c.getConfiguration(Configuration.class).getValueType()); c.close(); }
Example 15
Source File: CacheManagerTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void create_cache2k_config_value_type_mismatch() { CachingProvider p = Caching.getCachingProvider(); CacheManager cm = p.getCacheManager(); MutableConfiguration cfg = ExtendedMutableConfiguration.of(new Cache2kBuilder<Long, Double>(){}); Cache<Integer, Double> cache = cm.createCache("aCache", cfg.setTypes(Long.class, Float.class)); cache.close(); }
Example 16
Source File: CacheManagerTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test public void create_cache2k_config_nowrap() { CachingProvider p = Caching.getCachingProvider(); CacheManager cm = p.getCacheManager(); Cache<Long, Double> cache = cm.createCache("aCache", ExtendedMutableConfiguration.of( new Cache2kBuilder<Long, Double>(){} .entryCapacity(10000) .expireAfterWrite(5, TimeUnit.MINUTES) )); assertFalse(cache instanceof CopyCacheProxy); assertNull(cache.unwrap(org.cache2k.Cache.class).requestInterface(WiredCache.class)); cache.close(); }
Example 17
Source File: JCacheTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testGetAllHighVolume() 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); Map<String, String> m = new HashMap<>(); for (int i = 0; i < 10000; i++) { m.put("" + i, "" + i); } cache.putAll(m); Map<String, String> entries = cache.getAll(m.keySet()); assertThat(entries).isEqualTo(m); cache.close(); runner.stop(); }
Example 18
Source File: JCacheTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testGetAll() 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"); Map<String, String> entries = cache.getAll(new HashSet<String>(Arrays.asList("1", "3", "7"))); Map<String, String> expected = new HashMap<String, String>(); expected.put("1", "2"); expected.put("3", "4"); assertThat(entries).isEqualTo(expected); cache.close(); runner.stop(); }
Example 19
Source File: CacheManagerTest.java From cache2k with Apache License 2.0 | 5 votes |
@Test(expected=UnsupportedOperationException.class) public void no_online_listener_attachment_with_cache2k_defaults() { CachingProvider p = Caching.getCachingProvider(); CacheManager cm = p.getCacheManager(); MutableConfiguration cfg = ExtendedMutableConfiguration.of(new Cache2kBuilder<Long, Double>(){}); Cache cache = cm.createCache("mute", cfg); cache.registerCacheEntryListener(new CacheEntryListenerConfiguration() { @Override public Factory<CacheEntryListener> getCacheEntryListenerFactory() { fail("not expected to be called"); return null; } @Override public boolean isOldValueRequired() { return false; } @Override public Factory<CacheEntryEventFilter> getCacheEntryEventFilterFactory() { return null; } @Override public boolean isSynchronous() { return false; } }); cache.close(); }
Example 20
Source File: JCacheSetup.java From component-runtime with Apache License 2.0 | 4 votes |
public void releaseCache(@Disposes final Cache<String, DecryptedValue> cache) { cache.close(); }