protected ServerCache getDefaultCache() { GlobalConfiguration gconfig = new GlobalConfigurationBuilder() .globalJmxStatistics() .allowDuplicateDomains(true) .enable() .jmxDomain("custom-cache") .build(); Configuration configuration = new ConfigurationBuilder() .eviction() .strategy(EvictionStrategy.LIRS) .maxEntries(100) .jmxStatistics().enable() .build(); EmbeddedCacheManager manager = new DefaultCacheManager(gconfig, configuration); Cache<Object, Object> c = manager.getCache("custom-cache"); return new InfinispanCache(c); }
void evict() { builder.eviction() .strategy(EvictionStrategy.valueOf(options.getString(Caching.CreateOption.EVICTION).toUpperCase())) .maxEntries(options.getInt(Caching.CreateOption.MAX_ENTRIES)); } void expire() {
/** * Overrides the default embedded cache manager. */ @Produces @ApplicationScoped @SuppressWarnings("unused") public EmbeddedCacheManager defaultCacheManager() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.eviction().maxEntries(7); return TestCacheManagerFactory.createCacheManager(builder); }
@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"); }
/** * Creates a new ExoCache instance with the relevant parameters * @throws ExoCacheInitException If any exception occurs while creating the cache */ private ExoCache<Serializable, Object> create(ExoCacheConfig config, ConfigurationBuilder confBuilder, Callable<Cache<Serializable, Object>> cacheGetter, String strategy, int maxEntries, long lifespan, long maxIdle, long wakeUpInterval) throws ExoCacheInitException { EvictionStrategy es = strategy == null || strategy.length() == 0 ? null : EvictionStrategy.valueOf(strategy .toUpperCase(Locale.ENGLISH)); if (es == null) { es = EvictionStrategy.LRU; } confBuilder.eviction().strategy(EvictionStrategy.valueOf(strategy)).maxEntries(maxEntries).expiration() .lifespan(lifespan).maxIdle(maxIdle).wakeUpInterval(wakeUpInterval); try { return new GenericExoCache(config, cacheGetter.call()); } catch (Exception e)//NOSONAR { throw new ExoCacheInitException("Cannot create the cache '" + config.getName() + "'", e); } }
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"); }
/** * Associates the "small" and "large" caches with this specific cache manager. */ @Large @Small @Produces @ApplicationScoped @SuppressWarnings("unused") public EmbeddedCacheManager specificCacheManager() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.eviction().maxEntries(4000).strategy(EvictionStrategy.LIRS); return TestCacheManagerFactory.createCacheManager(builder); }
/** * <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; }
/** * 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(); }
/** * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements). * * @return an EHCache Cache instance containing the node id -> node mappings */ public Map getNodeCache() { if(nodeCache == null) { Configuration nodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration) .eviction() .maxEntries(1000000) .expiration() .lifespan(60, TimeUnit.MINUTES) .maxIdle(30, TimeUnit.MINUTES) .build(); cacheManager.defineConfiguration(NODE_CACHE, nodeConfiguration); nodeCache = new AsyncMap(cacheManager.getCache(NODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP)); } return nodeCache; }
/** * 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(); }
protected ServerCache getDefaultCache() { GlobalConfiguration gconfig = new GlobalConfigurationBuilder() .globalJmxStatistics() .allowDuplicateDomains(true) .enable() .jmxDomain("custom-cache") .build(); Configuration configuration = new ConfigurationBuilder() .eviction() .strategy(EvictionStrategy.LIRS) .maxEntries(100) .jmxStatistics().enable() .build(); EmbeddedCacheManager manager = new DefaultCacheManager(gconfig, configuration); Cache<Object, Object> c = manager.getCache("custom-cache"); return new InfinispanCache(c); }