package de.ronnyfriedland.knowledgebase.cache;

import javax.annotation.PostConstruct;

import org.apache.jcs.JCS;
import org.apache.jcs.access.CacheAccess;
import org.apache.jcs.access.exception.CacheException;
import org.springframework.stereotype.Component;

/**
 * @author ronnyfriedland
 */
@Component
public class RepositoryCache<T> {

    private CacheAccess cache = null;

    @PostConstruct
    public void init() throws Exception {
        cache = JCS.getInstance("default");
    }

    @SuppressWarnings("unchecked")
    public T get(final String key) {
        return (T) cache.get(key);
    }

    public void put(final String key, final T document) {
        try {
            cache.put(key, document);
        } catch (CacheException e) {
            // ignore
        }
    }

    public void remove(final String key) {
        try {
            T result = get(key);
            if (null != result) {
                cache.remove(result);
            }
        } catch (CacheException e) {
            // ignore
        }
    }
}

@@ -859,114 +859,26 @@
     
-T result = get(key);%0A            if (null != result) %7B%0A                cache.remove(result);%0A            %7D
+cache.remove(key);
 %0A   

remove elements by key instead of object in cache