package com.eactive.eai.transformer.layout;

import com.eactive.eai.transformer.util.Logger;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheException;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

// unused
public class ItemCache {
    private static Logger logger = Logger.getLogger("transformer");

    static Cache cache = null;    
    
    static {
        try {
            CacheManager manager = CacheManager.create();
            cache = new Cache("item", 1000, false, false, 0, 60);
            manager.addCache(cache);
        } catch(Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
    
    private ItemCache() {
    	
    }
    
    public static String get(String key) {
        try {
            Element element = cache.get(key);            
            if (element != null) {
                return (String)element.getObjectValue();
            }
            return null;
        } catch(CacheException e) {
            logger.error(e.getMessage(), e);
            return null;
        }    	
    }
    
    public static void put(String key, String value) {
    	cache.put(new Element(key, value));
    }
}    

