1.pom file
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>21.0</version> </dependency>
2.yaml profile
#spring配置
spring:
application:
name: cardmember
datasource:
cache:
type: guava
cache-names: merchantDetail,selConfig #缓存名字
guava:
spec: maximumSize=500,expireAfterWrite=5m
springboot type of caching support
public enum CacheType { GENERIC, JCACHE, EHCACHE, HAZELCAST, INFINISPAN, COUCHBASE, REDIS, CAFFEINE, /** @deprecated */ @Deprecated GUAVA, SIMPLE, NONE; private CacheType() { } }
3.service call
@Cacheable (value = "merchantDetail" ) public the Map checkMerchantInfo (String merchantId) { the Map <String, String> Map = merchantMapper.findAppCardMerchantById (merchantId); logger.info ( "------ Merchant Information acquired from the database - ----: {} " , Map); return Map; }
The most basic use, no other redundant configurations.