package id.iptek.utms.agent;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author jakar
 */
public final class GenericCache {
    
    private final static Map<String, GenericCache> caches = new HashMap<>();
    private final Map<String, Object> cache = new HashMap<>();
    
    private GenericCache() {}
    
    public void put(String name, Object value) {
        cache.put(name, value);
    }
    
    public Object get(String name) {
        return cache.get(name);
    }
    
    public void clear() {
        cache.clear();
    }
    
    public int size() {
        return cache.size();
    }
    
    public static GenericCache getCache(String name) {
        GenericCache cache = caches.get(name);
        if(cache == null) {
            cache = new GenericCache();
            caches.put(name, cache);
        }
        return cache;
    }
}
