• Documentation
  • Status: Resolved
  • 2 Major
  • Resolution: Fixed
  • cdennis
  • Reporter: didierl
  • July 31, 2012
  • 0
  • Watchers: 6
  • December 02, 2014
  • September 04, 2012

Description

The javadoc says: {quote} @return The value which must be Serializable. If not use #getObjectValue. *If the value is not Serializable, null is returned and an info log message emitted* {quote} However if the value is not Serializable, a {{CacheException}} is actually thrown. The only case it can return {{null}} is when the value is actually {{null}}.

It could also be interesting to document the advantage of using this method over {{getObjectValue()}} (if any?)

Comments

Chris Dennis 2012-09-04

I’ve fixed the javadoc, and also made the push to getObjectValue/Key stronger by deprecating getKey and getValue. There is no real advantage to using the Serializable returning methods they only exist for backward compatibility reasons.

Filippo Munafò 2014-11-07

Hi Chris, why did you write: “There is no real advantage to using the Serializable returning methods”? The documentation (http://goo.gl/sz194X) says to use getValue for getting “a Serializable value from an element” and getObjectValue for getting “a NonSerializable value from an element”. Moreover, from the element javadoc (http://www.ehcache.org/apidocs/2.9/net/sf/ehcache/Element.html):

“From ehcache-1.2, Elements can have keys and values that are Serializable or Objects. To preserve backward compatibility, special accessor methods for Object keys and values are provided: getObjectKey() and getObjectValue().”

but also, in contrast:

“If placing Objects in ehcache, developers must use the new getObject… methods to avoid CacheExceptions. The get… methods are reserved for Serializable keys and values.”

Moreover, from Element.getObjectValue javadoc:

“This method is provided for those wishing to use ehcache as a memory only cache and enables retrieval of non-Serializable values from elements.”

So, which method should I use for storing and retrieving “serializable Objects” having ehcache configured to use not only a memory store but also a disk store if getObjectValue is only for memory store and non-Serializable values and getValue, to be used for serializable values (Object?), is deprecated?

Thanks, Filippo

Filippo Munafò 2014-11-07

Better:

“So, which method should I use for retrieving “serializable Objects” having ehcache configured to use not only a memory store but also a disk store if getObjectValue is only for memory store and non-Serializable values and if getValue, to be used for serializable values (Object?), is deprecated?”

Filippo

Filippo Munafò 2014-11-24

Hi Chris, can you please take a look at my comment?

Thanks, Filippo

Gary Keim 2014-12-02

You use getObjectValue as that works for both Serializable (your case) and non-Serializable cases.