使用Oracle Coherence进行Spring缓存

时间:2014-02-17 13:28:20

标签: java spring caching oracle-coherence

我必须得到一个与Coherence一起使用的Spring Cache接口实现。据我所知,Spring或Coherence没有提供这样的实现(因为有ehcache,即)。所以,我必须自己做,我粘贴在底部。它在集成测试中运行良好,但我想知道是否有人遇到类似的问题,并对此代码有任何建议或更正。

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

}

1 个答案:

答案 0 :(得分:1)

您想看一下JSR-107(也称为JCache),这是正式的等效Spring自己的缓存注释added in Spring v3.1。完全认证的JCache支持应为in the next release of Oracle Coherence (v12.1.3)