Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid JBoss-Cache region from getting evicted?

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.

like image 779
hvrauhal Avatar asked Feb 17 '10 13:02

hvrauhal


1 Answers

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

like image 67
Eran Medan Avatar answered Oct 24 '22 11:10

Eran Medan