@Produces public Configuration customDefaultConfiguration() { return new ConfigurationBuilder() .eviction().maxEntries(16) .build(); } }
protected Cache getDefaultCache() { EmbeddedCacheManager manager = new DefaultCacheManager(); manager.defineConfiguration("custom-cache", new ConfigurationBuilder() .eviction().strategy(EvictionStrategy.NONE).maxEntries(1000) .build()); return manager.getCache("custom-cache"); }
public static void main(String args[]) throws Exception { EmbeddedCacheManager manager = new DefaultCacheManager(); manager.defineConfiguration("custom-cache", new ConfigurationBuilder() .eviction().strategy(LIRS).maxEntries(10) .build()); Cache<Object, Object> c = manager.getCache("custom-cache"); }
/** * <p>Defines the "large" cache configuration.</p> * * <p>This cache will be registered with the produced configuration in the default cache manager.</p> */ @Large @ConfigureCache("large") @Produces @SuppressWarnings("unused") public Configuration largeConfiguration() { return new ConfigurationBuilder() .eviction().maxEntries(1024) .build(); }
/** * <p>Configures a "tiny" cache (with a very low number of entries), and associates it with the qualifier {@link * Tiny}.</p> * * <p>This will use the default cache container.</p> */ @Tiny @ConfigureCache("tiny") @Produces public Configuration tinyConfiguration() { return new ConfigurationBuilder() .eviction().maxEntries(1) .build(); }
/** * <p>Defines the "very-large" cache configuration.</p> * * <p>This cache will be registered with the produced configuration in the specific cache manager.</p> */ @VeryLarge @ConfigureCache("very-large") @Produces @SuppressWarnings("unused") public Configuration veryLargeConfiguration() { return new ConfigurationBuilder() .eviction().maxEntries(4096) .build(); }
/** * <p>Configures a "small" cache (with a pretty low number of entries), and associates it with the qualifier {@link * Small}.</p> * * <p>This will use the default cache container.</p> */ @Small @ConfigureCache("small") @Produces public Configuration smallConfiguration() { return new ConfigurationBuilder() .eviction().maxEntries(10) .build(); } }
/** * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new * KiWiUriResources to avoid a database lookup. * * @return */ public Map getUriCache() { if(uriCache == null) { Configuration uriConfiguration = new ConfigurationBuilder().read(defaultConfiguration) .eviction() .maxEntries(config.getUriCacheSize()) .build(); cacheManager.defineConfiguration(URI_CACHE, uriConfiguration); uriCache = new AsyncMap(cacheManager.getCache(URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP)); } return uriCache; }
/** * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new * KiWiAnonResources to avoid a database lookup. * * @return */ public Map getBNodeCache() { if(bnodeCache == null) { Configuration bnodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration) .eviction() .maxEntries(config.getBNodeCacheSize()) .build(); cacheManager.defineConfiguration(BNODE_CACHE, bnodeConfiguration); bnodeCache = new AsyncMap(cacheManager.getCache(BNODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP)); } return bnodeCache; }
/** * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new * KiWiLiterals to avoid a database lookup. * * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String) * @return */ public Map getLiteralCache() { if(literalCache == null) { Configuration literalConfiguration = new ConfigurationBuilder().read(defaultConfiguration) .eviction() .maxEntries(config.getLiteralCacheSize()) .build(); cacheManager.defineConfiguration(LITERAL_CACHE, literalConfiguration); literalCache = new AsyncMap(cacheManager.getCache(LITERAL_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP)); } return literalCache; }
/** * Overrides the default embedded cache manager to define the quick and large cache configurations externally. */ @Produces @ApplicationScoped @SuppressWarnings("unused") public EmbeddedCacheManager defaultCacheManager() { EmbeddedCacheManager externalCacheContainerManager = TestCacheManagerFactory.createCacheManager(false); // define large configuration externalCacheContainerManager.defineConfiguration("large", new ConfigurationBuilder() .eviction().maxEntries(100) .build()); // define quick configuration externalCacheContainerManager.defineConfiguration("quick", new ConfigurationBuilder() .expiration().wakeUpInterval(1l) .build()); return externalCacheContainerManager; }
/** * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated * cache and should be used with care. * @return */ public Map getRegistryCache() { if(registryCache == null) { if(isClustered()) { Configuration registryConfiguration = new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.REPL_SYNC) .sync() .replTimeout(15, TimeUnit.SECONDS) .eviction() .strategy(EvictionStrategy.NONE) .build(); cacheManager.defineConfiguration(REGISTRY_CACHE, registryConfiguration); } else { Configuration registryConfiguration = new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.LOCAL) .eviction() .strategy(EvictionStrategy.NONE) .build(); cacheManager.defineConfiguration(REGISTRY_CACHE, registryConfiguration); } registryCache = cacheManager.getCache(REGISTRY_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP); } return registryCache; }
/** * Associates the "large" cache with the qualifier {@link Large}. * * @param cacheManager the specific cache manager associated to this cache. This cache manager is used to get the * default cache configuration. */ @Large @ConfigureCache("large") @Produces @SuppressWarnings("unused") public Configuration largeConfiguration(@Large EmbeddedCacheManager cacheManager) { return new ConfigurationBuilder() .read(cacheManager.getDefaultCacheConfiguration()) .eviction().maxEntries(2000) .build(); }
/** * Associates the "small" cache with the qualifier {@link Small}. * * @param cacheManager the specific cache manager associated to this cache. This cache manager is used to get the * default cache configuration. */ @Small @ConfigureCache("small") @Produces @SuppressWarnings("unused") public Configuration smallConfiguration(@Small EmbeddedCacheManager cacheManager) { return new ConfigurationBuilder() .read(cacheManager.getDefaultCacheConfiguration()) .eviction().maxEntries(20) .build(); }