• Bug
  • Status: Resolved
  • 2 Major
  • Resolution: Fixed
  • ehcache-core
  • ljacomet
  • Reporter: exposito
  • November 18, 2013
  • 0
  • Watchers: 4
  • December 23, 2013
  • December 06, 2013

Attachments

Description

Class net.sf.ehcache.store.LruPolicy is relying on method net.sf.ehcache.Element.getLastAccessTime() to perform eviction. However, getLastAccessTime() in class Element is not returning the Creation Time if newly created (as specified in the doc) when the Element is created using a constructor that doesn’t receive lastAccessTime.

Comments

Louis Jacomet Jacomet 2013-11-18

Hello,

Can you be a bit more explicit in what you are seeing and what you are expecting? A test would be a good way to convey that.

Thanks

Freddy Exposito 2013-11-19

Suggested patch for class net.sf.ehcache.ElementTest.

Freddy Exposito 2013-11-19

Hello Louis, Thanks for your response. I updated a patch to the existing test for Element.getLastAccessTime(). If I am understanding correctly the documentation for getLastAccessTime() (“Access means a get. So a newly created {@link Element} will have a last access time equal to its create time.”), the patched test should be the expected behavior.

Thanks

Louis Jacomet Jacomet 2013-11-28

Hello Freddy,

I see the issue with your changes in the test. However, this has nothing to do with the LruPolicy then. Because, when the element is put in the cache the first time, its access statistics are reset (see {{net.sf.ehcache.Cache#putInternal}} line 1527) and so the lastAccessTime is set to “now” (see {{net.sf.ehcache.Element#resetAccessStatistics}}). The possible change is to update the javadoc of {{getLastAccessTime()}} to clearly indicate that it has no semantic before the element is put in a cache.

Louis Jacomet Jacomet 2013-12-06

Javadoc of {{getLastAccessTime()}} has been improved to:

/**
 * Gets the last access time of this element.
 * 
 * Access means the element was written into a cache or read from it.
 * When first instantiated an {@link Element} has a lastAccessTime of 0, unless passed into the constructor.
 *
 * @see #Element(Object, Object, long, long, long, long, boolean, int, int, long) 
 * @see #Element(Object, Object, long, long, long, long, long)
 * @see #resetAccessStatistics() 
 * @see #updateAccessStatistics() 
 */