new SingleFileStoreConfigurationBuilder(persistConfig).location(location); fileStore.invocationBatching().enable(); fileStore.eviction().maxEntries(15); fileStore.eviction().strategy(EvictionStrategy.LRU); fileStore.jmxStatistics().disable(); final Configuration config = persistConfig.addStore(fileStore).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); }
/** * Clean the configuration template to prevent conflicts */ protected void resetConfiguration(ConfigurationBuilder confBuilder) { confBuilder.invocationBatching().enable().eviction().strategy(EvictionStrategy.NONE).maxEntries(-1).expiration() .lifespan(-1L).maxIdle(-1L).wakeUpInterval(60000L); } }
@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"); }
private org.infinispan.Cache<NotificationId, SubscriptionId> createCache() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.loaders() .passivation(true) .addFileCacheStore() .location(super.diskStorePath) .purgeOnStartup(true) .async() .eviction() .maxEntries( EventCloudProperties.SUBSCRIBER_CACHE_MAX_ENTRIES.getValue()) .strategy(EvictionStrategy.LRU) .locking() .isolationLevel(IsolationLevel.NONE); this.cacheManager.defineConfiguration("default", builder.build()); return this.cacheManager.<NotificationId, SubscriptionId> getCache("default"); }
/** * 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; }
/** * 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; }
/** * 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); }
/** * 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); } }
/** * <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(); }
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"); }
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); }
/** * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces * @return */ public Map getNamespacePrefixCache() { if(nsPrefixCache == null) { if(isClustered()) { Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration) .clustering() .cacheMode(CacheMode.REPL_ASYNC) .eviction() .maxEntries(config.getNamespaceCacheSize()) .expiration() .lifespan(1, TimeUnit.DAYS) .build(); cacheManager.defineConfiguration(NS_PREFIX_CACHE, nsprefixConfiguration); } else { Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration) .eviction() .maxEntries(config.getNamespaceCacheSize()) .expiration() .lifespan(1, TimeUnit.HOURS) .build(); cacheManager.defineConfiguration(NS_PREFIX_CACHE, nsprefixConfiguration); } nsPrefixCache = cacheManager.getCache(NS_PREFIX_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP); } return nsPrefixCache; }
configurationBuilder.eviction().maxEntries(123); configurationBuilder.expiration().maxIdle(180000); configurationBuilder.indexing()
/** * Create a non-clustered instance of the infinispan cache. */ public LDCachingInfinispanBackend() { globalConfiguration = new GlobalConfigurationBuilder() .classLoader(LDCachingInfinispanBackend.class.getClassLoader()) .globalJmxStatistics() .jmxDomain("org.apache.marmotta.ldcache") .allowDuplicateDomains(true) .build(); defaultConfiguration = new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.LOCAL) .eviction() .strategy(EvictionStrategy.LIRS) .maxEntries(100000) .expiration() .lifespan(7, TimeUnit.DAYS) .maxIdle(1, TimeUnit.DAYS) .build(); clustered = false; }
void evict() { builder.eviction() .strategy(EvictionStrategy.valueOf(options.getString(Caching.CreateOption.EVICTION).toUpperCase())) .maxEntries(options.getInt(Caching.CreateOption.MAX_ENTRIES)); } void expire() {
/** * <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(); }
/** * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces * @return */ public Map getNamespaceUriCache() { if(nsUriCache == null) { if(isClustered()) { Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration) .clustering() .cacheMode(CacheMode.REPL_ASYNC) .eviction() .maxEntries(config.getNamespaceCacheSize()) .expiration() .lifespan(1, TimeUnit.DAYS) .build(); cacheManager.defineConfiguration(NS_URI_CACHE, nsuriConfiguration); } else { Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration) .eviction() .maxEntries(config.getNamespaceCacheSize()) .expiration() .lifespan(1, TimeUnit.HOURS) .build(); cacheManager.defineConfiguration(NS_URI_CACHE, nsuriConfiguration); } nsUriCache = new AsyncMap(cacheManager.getCache(NS_URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP)); } return nsUriCache; }
/** * Build a local cache configuration. * <p/> * In local cache mode, the cache is not shared among the servers in a cluster. Each machine keeps a local cache. * This allows quick startups and eliminates network traffic in the cluster, but subsequent requests to different * cluster members cannot benefit from the cached data. */ protected void buildLocalConfiguration() { GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder() .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader()) .globalJmxStatistics() .jmxDomain("org.apache.marmotta.kiwi") .allowDuplicateDomains(true) .build(); defaultConfiguration = new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.LOCAL) .eviction() .strategy(EvictionStrategy.LIRS) .maxEntries(100000) .expiration() .lifespan(5, TimeUnit.MINUTES) .maxIdle(1, TimeUnit.MINUTES) .build(); cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true); log.info("initialised Infinispan local cache manager"); }