Subversion Repositories SmartDukaan

Rev

Rev 3561 | Rev 11872 | 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";
3273 vikas 12
    public static final String SEARCH_SNIPPET_CACHE_NAME = "SearchSnippets";
10232 kshitij.so 13
    public static final String BANNER_CACHE_NAME ="BannerCache";
3242 vikas 14
 
3561 rajveer 15
    public static enum CacheKeys{
16
    	HOME_PAGE_SNIPPET_CACHE_KEY,
17
    	SHOWCASE_PAGE_SNIPPET_CACHE_KEY,
18
    	PRODUCT_PAGE_SNIPPET_CACHE_KEY,
19
    	CATEGORY_SNIPPET_CACHE_KEY,
10232 kshitij.so 20
    	SEARCH_SNIPPET_CACHE_KEY,
21
    	BANNER_CACHE_KEY
3561 rajveer 22
    }
23
 
3050 vikas 24
    private final String cacheName;
25
    private final CacheManager cacheManager;
26
 
27
    public EhcacheWrapper(final String cacheName, final CacheManager cacheManager)
28
    {
29
        this.cacheName = cacheName;
30
        this.cacheManager = cacheManager;
31
    }
32
 
33
    public void put(final K key, final V value)
34
    {
35
        getCache().put(new Element(key, value));
36
    }
37
 
3268 chandransh 38
    @SuppressWarnings("unchecked")
3050 vikas 39
    public V get(final K key) 
40
    {
41
        Element element = getCache().get(key);
42
        if (element != null) {
43
            return (V) element.getObjectValue();
44
        }
45
        return null;
46
    }
47
 
48
    public void removeAll() 
49
    {
50
        getCache().removeAll();
51
    }
52
 
53
    public void remove(final K key) 
54
    {
55
        getCache().remove(key);
56
    }
57
 
58
    public Ehcache getCache() 
59
    {
60
        return cacheManager.getEhcache(cacheName);
61
    }
62
}