In my experience, you wouldn't want the map to return null if the time
has expired.  You would want it to return a "refreshed" value.  So,
you would want to have the user provide a RefreshProvider (or whatever
you want to call it):

public interface RefreshProvider
{
 public Object getValueForKey( Object key );
}

That way, if the value is expired, it could check with the provider to
get a fresh copy of the value.


On 2/7/07, Stephen Colebourne <[EMAIL PROTECTED]> wrote:
This sounds a little too specific for me. I suspect that most people
that want an expiring map will want it to be active not passive.

Stephen


Elifarley wrote:
> I've developed a Map decorator which passively evicts expired entries once 
their
> expiry time has been reached.
>
> When putting an item in the map, the decorator calls the 'expiryTime' method,
> passing the key and the value as parameters, and uses the returned value as 
the
> expiry time for that entry.
>
> The default implementation of 'expiryTime' just assigns a time 60 seconds in 
the
> future for every entry, but subclasses can provide their own policy.
>
> When getting the value for an entry, its expiry time is checked, and if its
> greater than the current time, the value is returned. Otherwise, the entry is
> removed from the decorated map, and null is returned.
> Doing so, there's no need to have a separate, active thread (hence the name
> 'passive') to check expiry times - the check is performed on demand.
>
> I've developed it for my own use, but maybe this could be useful to others 
too.
>
> Any thoughts ?
>
> Regards,
> Elifarley
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to