Spring Boot @EnableCaching : 2018 | @Cacheable | @CachePut | @CacheEvict | @Caching

Publicado el: 28 febrero 2018
en el canal de: Learning and Teaching
2,540
16

In this video we will learn how to implement caching for Spring Boot

Lets see what is Spring Cache?
Spring cache is an abstract framework where Spring only provides the layer where other
third party caching implementations can be plugged in for storing data.
Hence, Spring does not provide any cache storage implementations where as it facilitates or allows to use caching mechanisms of user's choice.

When should we use cache?
Caching is supported for the methods. It's efficient to to use when the methods return the same result for the given input for the multiple invocations.

What does Spring provide us?
Spring provides a concept called Cache Abstraction. The idea is to provide a set of annotations to manage the caches.
So, to achieve cache abstraction we apply caching to Java methods, reducing the number of invocations.

What happens?
So, When a method with caching behavior is being invoked it checks whether the method has been already executed for the given arguments.
if true, the cached result is returned without executing the method
if false, the method is executed, result is stored so that from now on whenever this method is executed, the cache result is returned.

Hence, we restrict method invokation if the input is the same and check if the method is already being invoked

Spring Cache annotations :

@EnableCaching annotation is used to convey the framework that we are using Cache Abstraction feature for this project.

1.@Cacheable :if multiple requests are received by the application, then this annotation will not execute the method multiple times, instead it will send the result from the cached storage.

2.@CachePut: Update a cache entry

3.@CacheEvict:used for removing a single cache or clearing the entire cache from the cache storage.
If you set the allEntries=true, then, the entire cache will be cleared.

4.@Caching :allows multiple nested @Cacheable, @CachePut and @CacheEvict to be used on the same method

5.@CacheConfig: we annotate @CacheConfig at the class level to avoid repeated mentioning in each method.
If you have multiple operations in a class where each operation has to be given cache configuration details, this could be a tedious job.


En esta página del sitio puede ver el video en línea Spring Boot @EnableCaching : 2018 | @Cacheable | @CachePut | @CacheEvict | @Caching de Duración hora minuto segunda en buena calidad , que subió el usuario Learning and Teaching 28 febrero 2018, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 2,540 veces y le gustó 16 a los espectadores. Disfruta viendo!