Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Bean(destroyMethod="shutdown")
- public net.sf.ehcache.CacheManager ehCacheManager()
- {
- //default config
- CacheConfiguration cacheConfiguration = new CacheConfiguration();
- cacheConfiguration.setName("myCacheName");
- cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
- cacheConfiguration.setMaxEntriesLocalHeap(1000000);
- //cacheConfiguration.setOverflowToDisk(true);
- cacheConfiguration.setEternal(false);
- cacheConfiguration.setMaxEntriesLocalDisk(1000000);
- cacheConfiguration.setTimeToLiveSeconds(3600);
- cacheConfiguration.setStatistics(true);
- cacheConfiguration.addPersistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP));
- net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
- config.addDefaultCache(cacheConfiguration);
- config.addDiskStore(new DiskStoreConfiguration().path("C:/myDiskStore"));
- //dynamic scenario cache
- net.sf.ehcache.Cache dynamicScenarioCache = new net.sf.ehcache.Cache(cacheConfiguration);
- dynamicScenarioCache.setName("dynamicScenario");
- //Ehcache manager
- net.sf.ehcache.CacheManager manager = net.sf.ehcache.CacheManager.create(config);
- manager.addCache(dynamicScenarioCache);
- //monitor stats
- MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
- ManagementService.registerMBeans(manager, mBeanServer, false, false, false, true);
- return manager;
- }
- @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "dynamicScenario")
- @Entity
- @Table(name="DynamicScenarioTable")
- @JsonIgnoreProperties({/** to be specified */})
- @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "dynamicScenario")
- public class DynamicScenario implements java.io.Serializable
- .....
- getSession().createQuery("from DynamicScenario").list();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement