Introduction :
We can enable cache in spring by the use of @EnableCaching and @Cachable.Refer Video Tutorial For Detail :
@EnableCaching
The annotation @EnableCaching should be used on the class level to configure the class for enabling cache. This annotation should be used to make it configurable for cache maintenance.
@EnableCaching //provided annotation on class level public class CachingDemo{ //Custom Code } |
@Cachable
The annotation @Cachable should be used above the methods which needs to maintain cache.
Once the request is complete the response is stored in cache for same request coming in future.
The response is mapped to the key for further requests.
@Cacheable("userInfo") //provided cacheable annotation along with userInfo as key public String checkCache() { //Custom Code } |
Conclusion
Major annotation to be used for caching in spring is @EnableCaching and @Cachable. The key should be provide where the cached is used so that the cache data should be mapped to the key.
No comments:
Post a Comment