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 ?
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.
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 .
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.
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.
There are lots of links to learn from
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With