• Bug
  • Status: Closed
  • Resolution: Fixed
  • drb
  • Reporter: sourceforgetracker
  • September 21, 2009
  • 0
  • Watchers: 0
  • September 22, 2009
  • September 22, 2009


would it be possible to extend ehcache to have multiple keys pointing to the same cached element, without having an overhead of multiple copies of the element!? At the time i retrieve data objects from my db i know all possible alias keys which might be used to retrieve the same object from db or cache. At this time i want to put the same element with multiple keys in the cache.

a new cache.put(Serializable key, Element element) is needed.

Following testcase should work:

… Cache myCache; …

Element cachedElement = new Element(“key1”,”my cached value”);

myCache.put(cachedElement); myCache.put(“key2”, cachedElement); myCache.put(“key3”, cachedElement); myCache.put(“key4”, cachedElement);

assertEquals(“my cached value”, (String)myCache.get(“key1”).getValue());

assertEquals(“my cached value”, (String)myCache.get(“key2”).getValue());

assertEquals(“my cached value”, (String)myCache.get(“key3”).getValue());

assertEquals(“my cached value”, (String)myCache.get(“key4”).getValue()); …

thanks in advance, thomas Sourceforge Ticket ID: 1737579 - Opened By: oberinspector - 15 Jun 2007 02:19 UTC


Sourceforge Tracker 2009-09-21

Logged In: YES user_id=693320 Originator: NO


Obviously it will work if you are using MemoryStore only with no serialization with the same value put into multiple elements. The overhead for an element is actually pretty low. Here are the fields:

private long version;
private long creationTime;
private long lastAccessTime;
private long nextToLastAccessTime;
private long hitCount;
private int timeToLive;
private int timeToIdle;
private long lastUpdateTime;
private boolean eternal;
private boolean lifespanSet;

There does exist in some collections libraries the idea of a MultiMap, but that is where multiple values are returned in a collection by a key.

I think the best solution is to wear the small element overhead. Comment by: gregluck - 9 May 2008 01:51 UTC

Fiona OShea 2009-09-22

Re-opening so that I can properly close out these issues and have correct Resolution status in Jira