代码之家  ›  专栏  ›  技术社区  ›  hvrauhal tarsius

如何避免jboss缓存区域被逐出?

  •  11
  • hvrauhal tarsius  · 技术社区  · 16 年前

    我正在尝试为只在短时间内相关的数据创建一个jboss缓存。在此之后,应丢弃数据并释放相应的内存。

    缓存的组织方式如下:

    /my_region
        /session_1
            /datanode_1
              attribute1: value1
            /datanode_2
              attribute2: value2
        /session_2
            ...
        /session_3
            ...
        ...
        ...
    

    我的逐出策略配置如下:

    <attribute name="EvictionPolicyClass">org.jboss.cache.eviction.LRUPolicy</attribute> 
    <attribute name="EvictionPolicyConfig">
       <config>
          <attribute name="wakeUpIntervalSeconds">5</attribute>     
             <region name="/my_region">
         <attribute name="maxNodes">100</attribute>
         <attribute name="timeToLiveSeconds">1800</attribute>
            </region>
       </config>
    </attribute>
    

    有效:何时 /my_region 获取100个以上的子级,最近使用最少的子级将被逐出,以便区域缩小为100个子级。

    问题在于 LRUPolicy 当被逐出的节点有子节点时, they're not completely removed, but marked with jboss:internal:uninitialized: null instead . 此行为对于缓存以避免从持久性存储中获取它们的实体来说是有意义的,但它不适合缓存未持久化且永远不会被再次访问的实体。

    所以,为了删除节点,我创建了 卢旺达政策 用remove覆盖逐出。

    @Override
    public void evict(Fqn fqn) throws Exception {
        cache_.remove(fqn);
    }
    

    这项新政策不会离开 joss:internal:uninitialized: null 在后面,但是它移除了 / Myz区 节点何时 maxNodes 达到。当我把 卢旺达政策 在后面,我注意到区域节点本身实际上被逐出并得到 unitialized 标签,但最近使用的100个孩子仍然存在。

    我如何才能防止该地区本身被驱逐?有没有更好的方法来进行迁移而不是在不分离 eviction from expiration ?

    我使用的是jboss缓存版本1.3.0.sp4。

    2 回复  |  直到 13 年前
        1
  •  5
  •   Eran Medan    16 年前

    你有没有看 JBoss-Cache bugs repository ?


    编辑:

    看看这个jboss缓存错误,它似乎很有意义:

    https://jira.jboss.org/jira/browse/JBCACHE-921

    在1.4.1.sp1中修复

        2
  •  0
  •   mel3kings    13 年前

    通过编程,您可以将缓存区域设置为常驻:

    this.cache.getNode(fqn).setResident(true);