繁体   English   中英

以线程安全的方式重置Ehcache

[英]Reset Ehcache in a thread safe way

我在项目中使用Ehcache,并且有一个帮助器类:

public static void reset(Ehcache cache, List<MyClass> list) {
    List<Element> elementList = new ArrayList<Element>(list.size());
    for (MyClass myClass : list) {
        elementList.add(new Element(myClass.getId(), myClass));
    }
    // missing write lock
    cache.removeAll();
    // if findByKey(...) executed at this time, it's result will be null
    cache.putAll(elementList);
}

public static MyClass findByKey(Ehcache cache, Serializable key) {...
public static List<MyClass> findAll(Ehcache cache) {...
public static MyClass findFirstByQuery(Ehcache cache, Criteria criteria) {...
public static List<MyClass> findByQuery(Ehcache cache, Criteria criteria) {...
public static void put(Ehcache cache, MyClass myClass) {...

我需要同步方法。 我是否必须在所有方法中手动实现它,还是有其他方法(特定于Ehcache)呢?

从某种意义上来说,您就是一个人,Ehcache不会为此提供现成的解决方案。

您还需要意识到,根据更新的频率和运行时间,这可能会导致瓶颈。 您找不到执行此操作的其他模式吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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