Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package in.shop2020.serving.cache;
import in.shop2020.serving.utils.FileUtils;
import in.shop2020.serving.utils.Utils;

import java.io.File;
import java.io.IOException;

import net.sf.ehcache.CacheManager;

import org.apache.log4j.Logger;

public class SearchSnippetCacheWrapper
{
    private static Logger log = Logger.getLogger(SearchSnippetCacheWrapper.class);
    private static EhcacheWrapper<String, String> searchSnippetCache = new EhcacheWrapper<String, String>(
            EhcacheWrapper.SEARCH_SNIPPET_CACHE_NAME, CacheManager.create());;

    public static String getSnippet(String docId)
    {
        String snippet = searchSnippetCache.get(docId);
        if (snippet == null) {
            log.info("Loading search snippet from disk : " + docId);
            try {
                snippet = FileUtils.read(Utils.EXPORT_ENTITIES_PATH
                        + docId + File.separator + "SearchSnippet.html");
                if (snippet != null) {
                    searchSnippetCache.put(docId, snippet);
                }

            } catch (IOException e) {
                log.error(e);
            }
        }
        else {
            log.info("Loading search snippet from cache : " + docId);
        }
        return snippet;
    }
}