开发者

How to implement Self Populating EHcache?

开发者 https://www.devze.com 2023-02-03 05:54 出处:网络
Could you please give me the steps to implement SelfPouplatingEhcache. Regards, R开发者_运维知识库aju SelfPopulatingCache acts as a wrapper (or decorator) around another instance of EhCache. When you

Could you please give me the steps to implement SelfPouplatingEhcache.

Regards, R开发者_运维知识库aju


SelfPopulatingCache acts as a wrapper (or decorator) around another instance of EhCache. When you ask the SelfPopulatingCache for a cached value, and that value is not in the underlying cache, the SelfPopulatingCache will create the value for you. It does this using the CacheEntryFactory that you also provide.

So to create a SelfPopulatingCache, you need:

  • An instance of EhCache, which you fetch from the ChacheManager
  • An instance of CacheEntryFactory, which you write yourself.

Pass them both to the constructor of SelfPopulatingCache, and there you are.


SelfPopulatingCache cacheStatus = new SelfPopulatingCache(ehcache, new CacheEntryFactory() {
        @Override
        public Object createEntry(Object key) throws Exception {
            if (key.toString().equals(FLAG1)) {
                 return true;
            } else if (key.toString().equals(FLAG2)) {
                return false;
            }
            return null;
        }
     });
0

精彩评论

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