引入maven
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
//创建缓存
Cache<String, String> cache = CacheBuilder.newBuilder() .maximumSize(10000) .concurrencyLevel(10) .expireAfterWrite(30, TimeUnit.SECONDS) .build();
//设置缓存 cache.put("1", "xx");
//获取缓存,没有则返回null cache.getIfPresent("2"); //获取缓存,没有就设置一个 String v = cache.get("3", () -> "33");