Java Code Examples for org.cache2k.Cache2kBuilder#forUnknownTypes()
The following examples show how to use
org.cache2k.Cache2kBuilder#forUnknownTypes() .
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: Cache2kCacheFactory.java From joyrpc with Apache License 2.0 | 6 votes |
@Override public <K, V> Cache<K, V> build(final String name, final CacheConfig<K, V> config) { Cache2kBuilder<K, CacheObject<V>> builder = Cache2kBuilder.forUnknownTypes(); if (config.getKeyClass() != null) { builder.keyType(config.getKeyClass()); } builder.valueType(CacheObject.class); builder.permitNullValues(config.isNullable()); builder.entryCapacity(config.getCapacity() > 0 ? config.getCapacity() : Long.MAX_VALUE); if (config.getExpireAfterWrite() > 0) { builder.expireAfterWrite(config.getExpireAfterWrite(), TimeUnit.MILLISECONDS); } else { builder.eternal(true); } return new Cache2kCache<>(builder.build(), config); }
Example 2
Source File: Cache2kBuilderTest.java From cache2k with Apache License 2.0 | 6 votes |
private void cacheClosedEventFired(boolean _wiredCache) { final AtomicBoolean _FIRED = new AtomicBoolean(); Cache2kBuilder _builder = Cache2kBuilder.forUnknownTypes(); _builder = _builder.addCacheClosedListener(new CacheClosedListener() { @Override public void onCacheClosed(final Cache cache) { _FIRED.set(true); } }); if (_wiredCache) { StaticUtil.enforceWiredCache(_builder); } Cache c = _builder.build(); c.close(); assertTrue(_FIRED.get()); }
Example 3
Source File: LocalCache.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Constructor to instantiate LocalCache object. * * @param cacheBuilder CacheBuilder instance */ @SuppressWarnings("unchecked") public LocalCache( final CacheBuilder<V> cacheBuilder ) { Cache2kBuilder<?, ?> builder = Cache2kBuilder.forUnknownTypes(); if ( cacheBuilder.isExpiryEnabled() ) { builder.eternal( false ); if ( cacheBuilder.isRefreshExpiryOnAccess() ) { // TODO https://github.com/cache2k/cache2k/issues/39 is still // Open. Once the issue is resolved it can be updated here builder.expireAfterWrite( cacheBuilder.getExpiryInSeconds(), SECONDS ); } else { builder.expireAfterWrite( cacheBuilder.getExpiryInSeconds(), SECONDS ); } } else { builder.eternal( true ); } if ( cacheBuilder.getMaximumSize() > 0 ) { builder.entryCapacity( cacheBuilder.getMaximumSize() ); } // Using unknown typed key for builder and casting it this.cache2kInstance = (org.cache2k.Cache<String, V>) builder.build(); this.defaultValue = cacheBuilder.getDefaultValue(); }
Example 4
Source File: BasicCacheOperationsWithoutCustomizationsTest.java From cache2k with Apache License 2.0 | 5 votes |
protected Cache<Integer,Integer> createCache() { Cache2kBuilder b; if (pars.useObjectKey) { b = Cache2kBuilder.forUnknownTypes(); } else { b = Cache2kBuilder.of(Integer.class, Integer.class); } b.name(this.getClass().getSimpleName() + "-" + pars.toString().replace('=', '~')) .retryInterval(Long.MAX_VALUE, TimeUnit.MILLISECONDS) .entryCapacity(1000) .permitNullValues(true) .keepDataAfterExpired(pars.keepDataAfterExpired) .recordRefreshedTime(pars.recordRefreshTime) .disableStatistics(pars.disableStatistics); if (pars.withExpiryAfterWrite) { b.expireAfterWrite(TestingParameters.MAX_FINISH_WAIT_MILLIS, TimeUnit.MILLISECONDS); } else { b.eternal(true); } if (pars.withWiredCache) { StaticUtil.enforceWiredCache(b); } if (pars.withExpiryListener) { b.addListener(new CacheEntryExpiredListener() { @Override public void onEntryExpired(final Cache cache, final CacheEntry entry) { } }); } Cache<Integer,Integer> c = b.build(); if (pars.withEntryProcessor) { c = new EntryProcessorCacheWrapper<Integer, Integer>(c); } if (pars.withForwardingAndAbstract) { c = wrapAbstractAndForwarding(c); } return c; }
Example 5
Source File: Cache2kBuilderTest.java From cache2k with Apache License 2.0 | 4 votes |
@Test public void cacheNameUnique() { Cache2kBuilder _builder = Cache2kBuilder.forUnknownTypes(); _builder.name("hello", this.getClass(), "field"); assertEquals("hello~org.cache2k.test.core.Cache2kBuilderTest.field", _builder.toConfiguration().getName()); }
Example 6
Source File: Cache2kBuilderTest.java From cache2k with Apache License 2.0 | 4 votes |
@Test public void cacheNameUniqueNull() { Cache2kBuilder _builder = Cache2kBuilder.forUnknownTypes(); _builder.name(null, this.getClass(), "field"); assertEquals("org.cache2k.test.core.Cache2kBuilderTest.field", _builder.toConfiguration().getName()); }
Example 7
Source File: Cache2kBuilderTest.java From cache2k with Apache License 2.0 | 4 votes |
@Test(expected = NullPointerException.class) public void cacheNameException() { Cache2kBuilder _builder = Cache2kBuilder.forUnknownTypes(); _builder.name(this.getClass(), null); }
Example 8
Source File: Cache2kBuilderTest.java From cache2k with Apache License 2.0 | 4 votes |
@Test public void set_ExceptionPropagator() { Cache2kBuilder _builder = Cache2kBuilder.forUnknownTypes(); _builder.exceptionPropagator(new StandardExceptionPropagator()); assertNotNull(_builder.toConfiguration().getExceptionPropagator()); }
Example 9
Source File: Cache2kBuilderTest.java From cache2k with Apache License 2.0 | 4 votes |
@Test public void set_storeByReference() { Cache2kBuilder _builder = Cache2kBuilder.forUnknownTypes(); _builder.storeByReference(true); assertTrue(_builder.toConfiguration().isStoreByReference()); }