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