如何避免 JBoss-Cache 区域被驱逐?
我正在尝试为仅在短时间内相关的数据创建 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
的问题是,当被驱逐的节点有子节点时,它们并未完全删除,而是用 jboss:internal:uninitialized: null
标记。此行为对于缓存以避免从持久存储中获取它们的实体来说是有意义的,但它不适合缓存未持久且永远不会再次访问的实体。
因此,为了删除节点,我创建了一个 LRUPolicy
的扩展,它用删除覆盖了 evict。
@Override
public void evict(Fqn fqn) throws Exception {
cache_.remove(fqn);
}
这项新策略不会留下 joss:internal:uninitialized: null
的痕迹,但会在达到 maxNodes
时删除 /my_region
节点。当我将 LRUPolicy
放回去时,我注意到区域节点本身实际上被驱逐并获得了 unialized
标记,但 100 个最近使用的子节点仍然保留。
我怎样才能防止该地区本身被驱逐?有没有更好的方法来进行删除而不是驱逐,而不将 驱逐与过期分开?
我正在使用 jboss-cache 版本 1.3.0.SP4。
I'm trying to create a jboss-cache for data that is only relevant for a short period of time. After that time the data should be discarded and the respective memory freed.
The cache is organized like this:
/my_region
/session_1
/datanode_1
attribute1: value1
/datanode_2
attribute2: value2
/session_2
...
/session_3
...
...
...
And my eviction policy configuration looks like this:
<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>
This works: when /my_region
gets more than 100 children, the least recently used children are evicted so that the region shrinks back to 100 children.
The problem with the LRUPolicy
is that when the evicted nodes have children, they're not completely removed, but marked with jboss:internal:uninitialized: null
instead. This behaviour makes sense for entities that are cached to avoid fetching them from a persistent storage, but it is not suitable for caching entities that are not persisted and will never be accessed again.
So, to remove the nodes, I've created an extension of LRUPolicy
that overrides evict with remove.
@Override
public void evict(Fqn fqn) throws Exception {
cache_.remove(fqn);
}
This new policy does not leave joss:internal:uninitialized: null
's behind, but it removes the /my_region
node when maxNodes
is reached. When I put the LRUPolicy
back, I noticed that the region node itself actually gets evicted and gets the unitialized
tag, but the 100 most recently used children still remain.
How can I prevent the region itself from being evicted? Is there some better way to do the removal instead of eviction without separating the eviction from expiration?
I'm using jboss-cache version 1.3.0.SP4.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否查看过 JBoss-Cache bug 存储库?
编辑:
看看这个 JBoss-Cache 错误,它似乎非常相关:
https://jira.jboss.org/jira/browse/JBCACHE-921
已在 1.4.1.SP1 中修复
Did you look in the JBoss-Cache bugs repository?
Edit:
Take a look at this JBoss-Cache bug, it seems quite relevant:
https://jira.jboss.org/jira/browse/JBCACHE-921
Fixed in 1.4.1.SP1
通过编程,您可以将缓存区域设置为驻留区域:
Programmically you can set Cache region as a resident: