1

Could you please give me the steps to implement SelfPouplatingEhcache.

Regards, Raju

rajputhch
  • 627
  • 4
  • 22
  • 36

2 Answers2

3

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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • Hi thanks for your answer,I am configuring ehcaceh with by xml file.I able to fetch all th ehcahces in my servlet,Here i want to use SelfPopulatingCache to update the cache with some time,How to do that? – rajputhch Jan 10 '11 at 16:01
0
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;
        }
     });