Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. @Bean(destroyMethod="shutdown")
  2. public net.sf.ehcache.CacheManager ehCacheManager()
  3. {
  4. //default config
  5. CacheConfiguration cacheConfiguration = new CacheConfiguration();
  6. cacheConfiguration.setName("myCacheName");
  7. cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
  8. cacheConfiguration.setMaxEntriesLocalHeap(1000000);
  9. //cacheConfiguration.setOverflowToDisk(true);
  10. cacheConfiguration.setEternal(false);
  11. cacheConfiguration.setMaxEntriesLocalDisk(1000000);
  12. cacheConfiguration.setTimeToLiveSeconds(3600);
  13. cacheConfiguration.setStatistics(true);
  14. cacheConfiguration.addPersistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP));
  15.  
  16. net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
  17. config.addDefaultCache(cacheConfiguration);
  18. config.addDiskStore(new DiskStoreConfiguration().path("C:/myDiskStore"));
  19.  
  20. //dynamic scenario cache
  21. net.sf.ehcache.Cache dynamicScenarioCache = new net.sf.ehcache.Cache(cacheConfiguration);
  22. dynamicScenarioCache.setName("dynamicScenario");
  23.  
  24. //Ehcache manager
  25. net.sf.ehcache.CacheManager manager = net.sf.ehcache.CacheManager.create(config);
  26. manager.addCache(dynamicScenarioCache);
  27. //monitor stats
  28. MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
  29. ManagementService.registerMBeans(manager, mBeanServer, false, false, false, true);
  30. return manager;
  31. }
  32.  
  33. @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "dynamicScenario")
  34. @Entity
  35. @Table(name="DynamicScenarioTable")
  36. @JsonIgnoreProperties({/** to be specified */})
  37. @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "dynamicScenario")
  38. public class DynamicScenario implements java.io.Serializable
  39. .....
  40.  
  41. getSession().createQuery("from DynamicScenario").list();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement