I've gone through javax.cache.Cache
to understand it's usage and behavior. It's stated that,
JCache is a Map-like data structure that provides temporary storage of application data.
JCache and HashMap stores the elements in the local Heap memory and don't have persistence behavior by default. By implementing custom CacheLoader
and CacheWriter
we can achieve persistence. Other than that, When to use it?
Caches usually have more management logic than a map, which are nothing else but a more or less simple datastructure.
Some concepts, JCaches may implement
Some of these some are more general concepts of JCache, some are specific implementation details of cache providers
Here are the five main differences between both objects.
Unlike java.util.Map, Cache :
- do not allow null keys or values. Attempts to use null will result in a java.lang.NullPointerException
- provide the ability to read values from a javax.cache.integration.CacheLoader (read-through-caching) when a value being requested is not in a cache
- provide the ability to write values to a javax.cache.integration.CacheWriter (write-through-caching) when a value being created/updated/removed from a cache
- provide the ability to observe cache entry changes
- may capture and measure operational statistics
Source : GrepCode.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With