This post explains TouchedExpiryPolicy with simple example. TouchedExpiryPolicy is an expiry policy used to inform cache to remove entries which has exceeded its presence since last modification (which includes creation, access and update) Main Code 1 import java.util.Iterator; 2 3 import javax.cache.Cache; 4 import javax.cache.Cache.Entry; 5 import javax.cache.CacheManager; 6 import javax.cache.Caching; 7 import javax.cache.configuration.Factory; 8…… Continue reading JCache TouchedExpiryPolicy
Tag: jcache
Different ways to add entry in cache
This post explains the different ways provided by JCache to add entries in a cache. The api’s are as mentioned below 1) void put(K key, V value) –> Takes key and value as argument 2) void putAll(Map map) –> Takes a map as an argument 3) boolean putIfAbsent(K key, V value) –> Takes a key…… Continue reading Different ways to add entry in cache
JCache ModifiedExpiryPolicy
This post explains ModifiedExpiryPolicy with simple example. ModifiedExpiryPolicy is an expiry policy used to inform cache to remove entries which has exceeded its presence since last modification (which includes creation and update) Main Code 1 import java.util.Iterator; 2 3 import javax.cache.Cache; 4 import javax.cache.Cache.Entry; 5 import javax.cache.CacheManager; 6 import javax.cache.Caching; 7 import javax.cache.configuration.Factory; 8 import…… Continue reading JCache ModifiedExpiryPolicy
Different ways to remove cache entry
This post explains different ways in which we can remove entries in a cache using JCache api. The JCache api provides the below methods 1) boolean remove(K key) –> remove an entry with key matching the method parameter 2) boolean remove(K key, V oldValue) –> removes an entry with matching key and value 3) void…… Continue reading Different ways to remove cache entry
JCache Expiry Policy Example
This post explains about JCache’s Expiry policy with an example. Cache’s Expiry policy is used to inform the caching provider when to remove an entry. The below code uses JCache’s CreatedExpiryPolicy as an example. CreatedExpiryPolicy is used to inform the cache provider to remove the entry after a specified time since the entry’s addition to…… Continue reading JCache Expiry Policy Example
Replacing cache entry’s value
This post explains two ways provided by JCache api through, which we can replace the values of existing cache entry. JCache provides two apis for replacing the cache entry 1) replace(key, newValue) –> This api replaces an entry with matching key given in the method argument with newValue. It returns true when replaced else false.…… Continue reading Replacing cache entry’s value
JCache simple example
This post will be a simple introduction to JCache api. For this post and other future post related to JCache, I will be using Ehcache (a tool that provides caching facility). For the below example we need to know about the below terms. 1) CachingProvider 2) CacheManager 3) Cache 4) Configuration CachingProvider –> Represents the…… Continue reading JCache simple example