Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring 3.1 @Cacheable example

I am new to spring annotation and i want to create a sample example which shows the use of @Cacheable annotation in spring 3.1 does any one have guidance to create this ?

like image 690
Hemant Metalia Avatar asked Nov 02 '11 08:11

Hemant Metalia


People also ask

How does @cacheable work in spring?

The @Cacheable annotation takes care of putting the result into the cache. After the first call, the cached value is in the cache and stays there according to the cache configuration. When the method is called the second time, and the cache value has not been evicted yet, Spring will search for the value by the key.

How do you get a cacheable value?

It is totally possible other providers expose the Cache instance as a bean as well. If they don't, then the main way to get the cached value is by accessing the Cache from the CacheManager . I spoke to @Cacheable since the code snippet you shared in your question above made reference/use of @Cacheable .

What is key in @cacheable spring boot?

Any data stored in a cache requires a key for its speedy retrieval. Spring, by default, creates caching keys using the annotated method's signature as demonstrated by the code above. You can override this using @Cacheable's second parameter: key. To define a custom key you use a SpEL expression.


2 Answers

Hope following link may be helpful to you... A sample application.

Also have a look on Spring's documentation for cache abstraction and spring source blog post.

like image 75
Amit Avatar answered Oct 23 '22 02:10

Amit


There are lots of links to learn from

  • simple-spring-memcached
  • Cache Abstraction Spring 3.2
  • Spring Expression Language (SpEL) Spring 3.2
  • Cache abstraction in Spring 3/

I did a POC using spring cache, Simple Spring Memcached and Memcache. The svn link of working application code is here

Simple Spring Memcached – Spring Caching Abstraction and Memcached

like image 34
Niraj Singh Avatar answered Oct 23 '22 02:10

Niraj Singh