EHC ❯ Add EhCache.get(key, filter) ability
-
Bug
-
Status: Closed
-
-
Resolution: Fixed
-
-
-
drb
-
Reporter: sourceforgetracker
-
September 21, 2009
-
0
-
Watchers: 0
-
September 22, 2009
-
September 22, 2009
Description
It would be useful if you could pass in a filter to the EhCache.get() methods. This filter look something like this:
interface ElementFilter { boolean filter(Element element); }
The cache would fetch the element from the cache as normal, then pass it through the filter to determine whether or not to return it to the client.
My use case is that I have a cache with a TTL of 5 minutes. However, one of the cache’s clients is only interested in elements younger than 30 seconds. Currently, this client code gets the Element and manually checks the age of that element. However, this badly skews the cache stats, which records a cache hit, even though it isn’t really.
If the client here were able to pass in a filter which checked the element’s age, then the cache would only update the stats if the element matched the filter.
You could use the same filter construct in the various getKeys…() methods also. In fact, the specific getKeysWith…() methods could be deprecated and replaced with a single getKeys(Filter) method, with different filter implementsations. Sourceforge Ticket ID: 2128415 - Opened By: kennymacleod - 25 Sep 2008 13:25 UTC
Comments
Sourceforge Tracker 2009-09-21
Fiona OShea 2009-09-22
Re-opening so that I can properly close out these issues and have correct Resolution status in Jira
The problem with the use case is that we would need to call get anyway. If we called getQuiet to skip stats we would need to call get again to update the stats.
You can call getQuiet so as not to hit the cache.
If you have an answer to this let me know. Comment by: gregluck - 4 Apr 2009 07:37 UTC