Think about SpringBoot cache

We are using spring boot frame work and choose SimpleCacheManager to be the cache manager, scanned some references, there are also CompositeCacheManager and NoOpCacheManager, I thought that NoOpCacheManager was designed to make tests convenient, but what is the scene to use CompositeCacheManager and what is it different from SimpleCacheManager?

In the next part, I’ll show some codes to explain how we use SimpleCacheManager, if there is better strategy to use SimpleCacheManager?

To make the frame work, we need to add @EnableCaching at the entrance and add @Cacheable of the aim service method, cache manager implemented at the entrance.


public class Application {
  SimpleCacheManager cacheManager = new SimpleCacheManager();
  GuavaCache cache = new GuavaCache("ivan_cache",
  CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).build());
  return cacheManager();

Service module

@Cacheable(value = { "ivan_cache" })
public void cacheTest() {"Cache not effects.");

Refer to:



电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>