简体   繁体   中英

Spring cache with Oracle Coherence

I have to get a Spring Cache interface implementation that works with Coherence. As far as I could research, there is not such an implementation provided by Spring or Coherence (As there is for ehcache, ie). So, I had to make my own which I paste at the bottom. It works well on the integration tests, but I would like to know if someone has faced a similar problem, and has any suggestion or correction to this code.

import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;

public class MyCoherenceCache implements Cache {
    private final NamedCache cache;

    private static int instanceCounter = 0;

    @Override
    public synchronized void clear() {
        cache.clear();
    }

    @Override
    public synchronized void evict(Object object) {
        cache.remove(object);
    }

    @Override
    public synchronized ValueWrapper get(Object key) {
        if (cache.get(key) == null) {
            return null;
        } else {
            return new SimpleValueWrapper(cache.get(key));
        }
    }

    @Override
    public String getName() {
        return cache.getCacheName();
    }

    @Override
    public Object getNativeCache() {
        throw new RuntimeException("Error: Unimplemented method!");
    }

    @Override
    public synchronized void put(Object arg0, Object arg1) {
        cache.put(arg0, arg1);

    }

    MyCoherenceCache(String cacheName) {
        super();
        instanceCounter++;
        cache = CacheFactory.getCache(cacheName);
    }

    public static int getInstanceCounter() {
        return instanceCounter;
    }

}

You want to take a look at JSR-107 (also known as JCache) which is the formal equivalent Spring's own Caching annotations, added in Spring v3.1 . Fully certified JCache support should be in the next release of Oracle Coherence (v12.1.3)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM