Skip to content

Instantly share code, notes, and snippets.

Created May 18, 2010 21:03
Show Gist options
  • Save anonymous/405546 to your computer and use it in GitHub Desktop.
Save anonymous/405546 to your computer and use it in GitHub Desktop.
CacheManager cm = new CacheManager(getCacheConfig(elts, policy, ttl));
cache = cm.getCache("default");
// here cache == null;
private Configuration getCacheConfig(String elements, String policy, String ttl) {
Configuration configuration = new Configuration();
CacheConfiguration cfg = new CacheConfiguration();
cfg.setName("Any name here");
cfg.setMaxElementsInMemory(Integer.parseInt(elements));
cfg.setMemoryStoreEvictionPolicy(policy);
cfg.setTimeToLiveSeconds(Integer.parseInt(ttl));
cfg.setEternal(false);
cfg.setOverflowToDisk(false);
configuration.addCache(cfg);
configuration.addDefaultCache(cfg);
return configuration;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment