An issue where get comes out as null after using Ehcache to put an object into the cacheProblem
When you previously used Ehcache to cache data, the saved value was based on Java's underlying type data, and when you recently found the object that saved the custom type, the Get () element is either null or thrown when you use the element's GetValue () net.sf.ehcache.CacheException: Value xxx is not Serializableexception.
Solution Solutions
- Ehcache The object must be a serializable (Serializable) type when the object is put, that is, to implement the
java.io.Serializable。 This is because Ehcache is serialized when it is put on the object.
Official document Description of the Ehcache put method:
Put
Void put (element element) throws Illegalargumentexception,illegalstateexception, Cacheexception
Put An element in the cache.
resets the access statistics on the element, which would is the case if it had previously been gotten from a cache, an D is now being put back.
Also notifies the Cacheeventlistener that:
The element is put, but only if the element is actually put.
If the element exists in the cache, which an update had occurred, even if the element would be expired if it is reques Ted
Parameters:
Element-an object. If Serializable It can fully participate in replication and the Diskstore.
Throws:
Illegalstateexception-if The cache is not status.status_alive
Illegalargumentexception-if the Eleme NT is null
Cacheexception
In addition: the Flush () method of Ehcache is useful for serializing the cache to a file and caching the configuration Diskpersistent= "true". If the put does not have a serialized object and then Flush (), get () from the cache will get Null (the serialized object is not supported and cannot be persisted to the file). If there is no flush () after the put, you can get () to the cached element, but the exception is reported when the GetValue () of the element is called to fetch the cached object net.sf.ehcache.CacheException: Value xxx is not Serializable .
An issue where get comes out as null after using Ehcache to put an object into the cache