6 Replies Latest reply on Apr 27, 2005 10:07 AM by kkalmbach

    overriding LRUAlgorithm

    kkalmbach Newbie

      In my tinkering with the LRUAlgorithm, I often find myself wanting to change when a node is evicted (not just by how long it has been idle), but other than that, the LRUAlgorithm is fine. So, here is a small change to the LRU Algorithm I have been using that might be usable by someone else.

      Basically it takes the logic of looking at the idle time on a node and comparing it to the region's timeout and moves that logic into a method called shouldEvictNode. All my algorithms have to do is override "shouldEvictNode (usually calling super.shouldEvictNode), then do whatever other eviction I have set up.

      I hope it is useful to someone else.

      > protected boolean shouldEvictNode(NodeEntry entry, Region region, long currentTime) {
      > if(region.getTimeToLiveSeconds() == 0) return false; // no time limit
      > long idleTime = currentTime -entry.getModifiedTimeStamp();
      > return (idleTime >= (region.getTimeToLiveSeconds() *1000) );
      > }
      < if(region_.getTimeToLiveSeconds() == 0) return; // no time limit
      < Fqn fqn = cursor.getFqn();
      < long idleTime = currentTime -cursor.getModifiedTimeStamp();
      < cursor = cursor.getNext();
      < if(idleTime >= (region_.getTimeToLiveSeconds() *1000) ) {
      > if(shouldEvictNode(cursor, region_, currentTime)) {
      > Fqn fqn = cursor.getFqn();
      > cursor = cursor.getNext();