How Redis is used in a project

Source: Internet
Author: User

The use of the cache is to increase efficiency and avoid the wasteful efficiency of repetitive IO operations.

Query when used, such as Selectbyid value: Buffer name, key: The corresponding key in the buffer, indicating that the query buffer "user" key is the parameter ID of the cache, if not, query the database, And put the data in the cache (note that the cached data here refers to the result of the method's execution), and then fetch the data directly from the cache. @Cacheable (key = "#id", value = "User")

Used when querying, such as GetAll value: Cache name, key: not specified with default build policy (this project uses: Cn.my.base.RedisCacheConfig) @Cacheable (value = "Users")

Insert data using: The method @CachePut annotation must be executed, regardless of whether there is a cache, the return value of the method is placed in the cache @CachePut (value = "User", key = "#user. ID")

Use when deleting, updating: Beforeinvocation=true means deleting the cache before the method executes, regardless of whether the method executes successfully. Note that the cache must be removed cleanly, not only to delete the "user" buffer, but also to delete the "users" buffer @CacheEvict ( Key = "#user. id", value = "User", Beforeinvocation = True) @CacheEvict (value= "Users", allentries=true,beforeinvocation= True

Like the one above, to perform two or more cache operations, the combination cache operation is changed to @Caching (evict={@CacheEvict (key = "#user. id", value = "User", Beforeinvocation = t Rue), @CacheEvict (value= "users", Allentries=true,beforeinvocation=true)})

Learn more about Redis

http://xp9802.iteye.com/blog/2121997
http://blog.csdn.net/defonds/article/details/48716161

How Redis is used in a project

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.