SpringBoot series of 28 three: Cache

1, JSR107
the Java Caching defines five core interfaces are CachingProvider, CacheManager, Cache, Entry and Expiry.
CachingProvider defines create, configure, acquire, manage and control multiple CacheManager. An application can access multiple CachingProvider at runtime.
CacheManager defines create, configure, acquire, manage and control multiple uniquely named Cache, Cache these exist in the context of CacheManager. A CacheManager only a CachingProvider owned.
Cache is a data structure similar to the Map Key and temporarily stored as a value of the index. Cache is a only a CacheManager owned.
Entry is a key-value pairs stored in the Cache.
Expiry each stored in the Cache entry has a valid definition. Once over this time, the entry for the expired state. Once expired, the entry will not be accessible, update, and delete. Cache validity period can be set by ExpiryPolicy.
Here Insert Picture Description
2, Spring cache abstraction
 Spring version 3.1 defines org.springframework.cache.Cache and org.springframework.cache.CacheManager interfaces to unify different caching technology; and support the use of JCache (JSR-107) annotations simplify our development.
 Cache interface specification defines the cached component, including various set operations cache; Cache interface provides an implementation of the various Spring xxxCache; if RedisCache, EhCacheCache, ConcurrentMapCache like.
 Each time method requires the cache function calls the specified target method Spring will check whether the specified parameter has been called too; if you get the result of method calls directly from the cache, if you do not call the method and caches the results returned to the user. Next call is available directly from the cache.

When using Spring cache abstraction that we need to focus on the following two points:
 (1) determine the method needs to be cached as well as their cache policy;
 (2), before reading the data cache memory from the cache.
Here Insert Picture Description
3, cache comment
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/lizhiqiang1217/article/details/92071972