【问题标题】:Spring cache with Oracle Coherence使用 Oracle Coherence 的 Spring 缓存
【发布时间】:2014-02-17 13:28:20
【问题描述】:

我必须获得一个适用于 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;
    }

}

【问题讨论】:

  • 您面临什么样的问题?例外?
  • 实际上,我没有遇到任何问题。我只是想知道代码是否可以改进。或者是否可以避免一些潜在的问题。

标签: java spring caching oracle-coherence


【解决方案1】:

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

【讨论】:

猜你喜欢
  • 2013-06-19
  • 2018-06-29
  • 1970-01-01
  • 1970-01-01
  • 2015-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多