Subversion Repositories SmartDukaan

Rev

Rev 3242 | Rev 3273 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3242 vikas 1
package in.shop2020.serving.cache;
3050 vikas 2
import net.sf.ehcache.CacheManager;
3
import net.sf.ehcache.Ehcache;
4
import net.sf.ehcache.Element;
5
 
6
public class EhcacheWrapper<K, V> 
7
{
3112 vikas 8
    public static final String HOME_PAGE_SNIPPET_CACHE_NAME = "HomePageSnippets";
9
    public static final String SHOWCASE_PAGE_SNIPPET_CACHE_NAME = "ShowcasePageSnippets";
3225 vikas 10
    public static final String PRODUCT_PAGE_SNIPPET_CACHE_NAME = "ProductPageSnippets";
3242 vikas 11
    public static final String CATEGORY_SNIPPET_CACHE_NAME = "CategorySnippets";
12
 
3050 vikas 13
    private final String cacheName;
14
    private final CacheManager cacheManager;
15
 
16
    public EhcacheWrapper(final String cacheName, final CacheManager cacheManager)
17
    {
18
        this.cacheName = cacheName;
19
        this.cacheManager = cacheManager;
20
    }
21
 
22
    public void put(final K key, final V value)
23
    {
24
        getCache().put(new Element(key, value));
25
    }
26
 
3268 chandransh 27
    @SuppressWarnings("unchecked")
3050 vikas 28
    public V get(final K key) 
29
    {
30
        Element element = getCache().get(key);
31
        if (element != null) {
32
            return (V) element.getObjectValue();
33
        }
34
        return null;
35
    }
36
 
37
    public void removeAll() 
38
    {
39
        getCache().removeAll();
40
    }
41
 
42
    public void remove(final K key) 
43
    {
44
        getCache().remove(key);
45
    }
46
 
47
    public Ehcache getCache() 
48
    {
49
        return cacheManager.getEhcache(cacheName);
50
    }
51
}