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
Tag: Spring Framework
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
Ordering multiple BeanPostProcessor implementations example
In this post under Spring Core, I will show with example how to order multiple “BeanPostProcessor” interface implementations. To order multiple “BeanPostProcessor” implementations, each implementations much implement “Ordered” interface and provide order number in the interface “getOrder” method. Note: Ordering of “BeanPostProcessor” implementations only work with “@Component” annotation and not with “@Bean” annotation. For our…… Continue reading Ordering multiple BeanPostProcessor implementations example
BeanFactoryPostProcessor example
In this post under Spring Core, I will explain with example the purpose of “BeanFactoryPostProcessor” Spring class. We define our Spring beans and give it to Spring container to create instances of those beans. Spring container reads the bean definitions and create instances of beans. What if we want to change the definition of those…… Continue reading BeanFactoryPostProcessor example
Implementing instance factory method using Spring annotations
In this post under Spring Core, I will show how to implement instance factory method using Spring annotations instead of using xml approach. For our example, lets create “Calculator” class with below structure, whose bean we have to create using instance factory method Calculator package core.package53; public class Calculator { public void calculate() { System.out.println(“Calculating….”);…… Continue reading Implementing instance factory method using Spring annotations