Conditional caching using SpEL

In this post under Spring Caching, I will show with example how to enable conditional caching using SpEL. In previous posts I showed you how to use “@Cacheable” annotation. In that annotation itself there is an attribute that we can use to enable conditional caching. That attribute name is “condition” and it takes as SpEL…… Continue reading Conditional caching using SpEL

Creating custom cache key from target object properties using SpEL

In this post under Spring Caching, I will show with example how to create custom cache key using annotated method’s target object properties in SpEL. For our example, we will use the below “Calculator” class as shown below Calculator package caching.package8; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Component; @Component public class Calculator { private int start, end; @Cacheable(cacheNames…… Continue reading Creating custom cache key from target object properties using SpEL

Creating custom cache key from method object properties using SpEL

In this post under Spring Caching, I will show with example how to create custom cache key using annotated method’s properties in SpEL. For our example, we will use the below “Calculator” class as shown below Calculator package caching.package7; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Component; @Component public class Calculator { @Cacheable(cacheNames = "addNumbersWithParam_region", key = "#root.method.hashCode() +…… Continue reading Creating custom cache key from method object properties using SpEL

Creating custom cache key from method name using SpEL

In this post under Spring Caching, I will show with example how to create custom cache key from method name using SpEL. In SpEL, to access SpEL context object we will use “#root” variable. This SpEL context object will have below information reference to target method that is annotated with @Cacheable, @CachePut, or @CacheEvict reference…… Continue reading Creating custom cache key from method name using SpEL

Creating custom cache key from method arguments using SpEL

In this post under Spring Caching, I will show with example how to create custom cache key from method arguments in SpEL. In SpEL, to access SpEL context object we will use “#root” variable. This SpEL context object will have below information reference to target method that is annotated with @Cacheable, @CachePut, or @CacheEvict reference…… Continue reading Creating custom cache key from method arguments using SpEL

Default cache key in Spring Caching

In this post under Spring Caching, I will explain with example what default cache key are used when storing data in the cache and you don’t specify your own cache key. Spring Caching out of the box determines the cache key using the method parameters. If a method has no parameters, the key will be…… Continue reading Default cache key in Spring Caching

Spring Caching Simple (@Cacheable) Example Class Level Part 2

In this post under Spring Caching, I will show with example how “@Cacheable” at class level affects the functioning of the class method. In previous post I have already explained how to enable and use caching at class level but with a class having just one single method. Below is the “Calculator” class that I…… Continue reading Spring Caching Simple (@Cacheable) Example Class Level Part 2

Spring Caching Simple (@Cacheable) Example Class Level Part 1

In this post under Spring Caching, I will show with example how to enable and use caching at class level in Spring application. For our example, we will use “Calculator” class which has “calculate” method which will perform heavy calculation. It will perform summation from 1 to 1000000. We cannot perform the calculation every time,…… Continue reading Spring Caching Simple (@Cacheable) Example Class Level Part 1

Spring Caching Simple (@Cacheable) Example Method Level

In this post under Spring Caching, I will show with example how to enable and use caching in Spring application. For our example, we will use “Calculator” class which has “calculate” method which will perform heavy calculation. It will perform summation from 1 to 1000000. We cannot perform the calculation every time, so we have…… Continue reading Spring Caching Simple (@Cacheable) Example Method Level