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
        }
    }
}

@@ -784,11 +784,263 @@
  %7D%0A    %7D
+%0A%0A    public void remove(final String key) %7B%0A        try %7B%0A            T result = get(key);%0A            if (null != result) %7B%0A                cache.remove(result);%0A            %7D%0A        %7D catch (CacheException e) %7B%0A            // ignore%0A        %7D%0A    %7D
 %0A%7D%0A

add method toe remove element from cache