Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3242 vikas 1
package in.shop2020.serving.cache;
2
import in.shop2020.serving.utils.FileUtils;
3
import in.shop2020.serving.utils.Utils;
4
 
5
import java.io.File;
6
import java.io.IOException;
7
 
8
import net.sf.ehcache.CacheManager;
9
 
10
import org.apache.log4j.Logger;
11
 
12
public class CategorySnippetCacheWrapper
13
{
14
    private static Logger log = Logger.getLogger(CategorySnippetCacheWrapper.class);
15
    private static EhcacheWrapper<String, String> categorySnippetCache = new EhcacheWrapper<String, String>(
16
            EhcacheWrapper.CATEGORY_SNIPPET_CACHE_NAME, CacheManager.create());;
17
 
18
    public static String getSnippet(String docId)
19
    {
20
        String snippet = categorySnippetCache.get(docId);
21
        if (snippet == null) {
22
            log.info("Loading category snippet from disk : " + docId);
23
            try {
24
                snippet = FileUtils.read(Utils.EXPORT_ENTITIES_PATH
25
                        + docId + File.separator + "CategorySnippet.html");
26
                if (snippet != null) {
27
                    categorySnippetCache.put(docId, snippet);
28
                }
29
 
30
            } catch (IOException e) {
31
                log.error(e);
32
            }
33
        }
34
        else {
35
            log.info("Loading category snippet from cache : " + docId);
36
        }
37
        return snippet;
38
    }
39
}