[ 
https://issues.apache.org/jira/browse/COLLECTIONS-467?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13656942#comment-13656942
 ] 

l0co commented on COLLECTIONS-467:
----------------------------------

Sure, listener interface would be much better than the creation of anonymous 
inherited class. My example was done as simple as possible for one usage in app.

PassiveExpiringMap looks doing exactly the same as my own implementation, 
although was not present in 3.2 which is used in our project. I have two 
remarks about this. I additionally keep the value of the next element timeout 
(the youngest timeout) in object field, so that I don't need to iterate through 
whole map to find elements for expiration on each call. It improves performance 
by calculating only simple if for most cases:

{code}
public class PassiveExpiringMap {
  long youngestTimeoutMs = 0; // assert to have next timeout time for youngest 
element here always, or 0 if map is empty
  
  private void removeAllExpired(final long now) {
    if (youngestTimeoutMs>0 && youngestTimeoutMs<=now) {
      // do the cleanup
    }
  }
}
{code}

The second remark concerns the refreshing policy. As I can see there's no 
refreshing policy in current implementation, there should be at last two 
policies: NoRefresh (working as the current) and RefreshOnHit - which updates 
element expiration time when the element is "hit" (eg. by get()), so that the 
map always removes the least used resources.
                
> LRUMap remove callback
> ----------------------
>
>                 Key: COLLECTIONS-467
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-467
>             Project: Commons Collections
>          Issue Type: New Feature
>    Affects Versions: 3.2
>            Reporter: l0co
>            Priority: Minor
>             Fix For: 4.x
>
>
> If you use LRUMap with objects that require doing some disposal when they are 
> dropped (eg. close()) and you hold these objects only in LRUMap, you cannot 
> do it with current implementation. I propose to add onRemove() and onAdd() 
> methods to the implementation, so that you can create anonymous inherited 
> class and be able to react to these events.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to