开发者

2-level cache in java

How can I organize a 2 level cache in Java?

  • 1st level - memory
  • 2nd level - filesystem
开发者_如何学运维

Where I can find information about 2 level cache implementation and cache strategies configuration or can you show me any methods that can solve this problem.


I suggest using imcache and load necessary items from disk using cache loader as follows,

Cache<String,Object> yourCache = CacheBuilder.
   concurrentHeapCache().cacheLoader(new CacheLoader<String, Object>() {
   public Object load(String key) {
   //code to load item from file.
   }
}).build();  


It looks like using option 2 with overwrite to disk option will work for OP. These 2 urls can help: http://memcached.org/ and http://ehcache.org/


Not clear what your question is, if you are talking about hibernate 2nd level caching, see here http://www.javalobby.org/java/forums/t48846.html

If you just want to know how to cache in java, then you have a few options 1.) Store the data in a HashMap 2.) Use Memcached 3.) Store it in a file 4.) Store it in a database

Each have their trade-offs, we would need to know more about your problem to advise.


I have used OS Cache - http://www.opensymphony.com/oscache/wiki/Feature%20List.html And found it one of the best ways to implement 2 level caching.

  1. It works like a hashmap with key value pairs.

  2. It transparently stores the most used data in memory and then swaps the rest to the file system(you can change the algorithm)

  3. It scales up really well. Even for a large number of objects it does not show any performance degradation

  4. It supports clustering as well

  5. It is highly configurable

  6. It is FREE and Open Source!


I've build something that can be useful for your needs.

https://github.com/enryold/onion-cache

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜