Java Code Examples for org.springframework.cache.support.SimpleCacheManager

The following examples show how to use org.springframework.cache.support.SimpleCacheManager. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ProxyPool   Source File: CacheConfig.java    License: Apache License 2.0 7 votes vote down vote up
/**
 * 创建基于Caffeine的Cache Manager
 * @return
 */
@Bean
@Primary
public CacheManager caffeineCacheManager() {
    SimpleCacheManager cacheManager = new SimpleCacheManager();

    ArrayList<CaffeineCache> caches = new ArrayList<CaffeineCache>();
    for(Caches c : Caches.values()){
        caches.add(new CaffeineCache(c.name(),
                Caffeine.newBuilder().recordStats()
                        .expireAfterWrite(c.getTtl(), TimeUnit.SECONDS)
                        .maximumSize(c.getMaxSize())
                        .build())
        );
    }

    cacheManager.setCaches(caches);

    return cacheManager;
}
 
Example 2
Source Project: spring-boot-101   Source File: CacheConfig.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 创建基于Caffeine的Cache Manager
 * @return
 */
@Bean
@Primary
public CacheManager caffeineCacheManager() {
	SimpleCacheManager cacheManager = new SimpleCacheManager();
	
	ArrayList<CaffeineCache> caches = new ArrayList<CaffeineCache>();
	for(Caches c : Caches.values()){
		caches.add(new CaffeineCache(c.name(), 
			Caffeine.newBuilder().recordStats()
			.expireAfterWrite(c.getTtl(), TimeUnit.SECONDS)
			.maximumSize(c.getMaxSize())
			.build())
		);
	}
	
	cacheManager.setCaches(caches);

	return cacheManager;
}
 
Example 3
/**
 * 个性化配置缓存
 */
@Bean
public CacheManager cacheManager() {
    SimpleCacheManager manager = new SimpleCacheManager();
    //把各个cache注册到cacheManager中,CaffeineCache实现了org.springframework.cache.Cache接口
    ArrayList<CaffeineCache> caches = new ArrayList<>();
    for (Caches c : Caches.values()) {
        caches.add(new CaffeineCache(c.name(),
                Caffeine.newBuilder().recordStats()
                        .expireAfterWrite(c.getTtl(), TimeUnit.SECONDS)
                        .maximumSize(c.getMaxSize())
                        .build())
        );
    }
    manager.setCaches(caches);
    return manager;
}
 
Example 4
Source Project: spring-analysis-note   Source File: CacheTestUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Create a {@link SimpleCacheManager} with the specified cache(s).
 * @param cacheNames the names of the caches to create
 */
public static CacheManager createSimpleCacheManager(String... cacheNames) {
	SimpleCacheManager result = new SimpleCacheManager();
	List<Cache> caches = new ArrayList<>();
	for (String cacheName : cacheNames) {
		caches.add(new ConcurrentMapCache(cacheName));
	}
	result.setCaches(caches);
	result.afterPropertiesSet();
	return result;
}
 
Example 5
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager mgr = new SimpleCacheManager();
	ArrayList<Cache> caches = new ArrayList<>();
	caches.add(new ConcurrentMapCache(""));
	mgr.setCaches(caches);
	return mgr;
}
 
Example 6
Source Project: spring-analysis-note   Source File: AbstractJCacheTests.java    License: MIT License 5 votes vote down vote up
protected static CacheManager createSimpleCacheManager(String... cacheNames) {
	SimpleCacheManager result = new SimpleCacheManager();
	List<Cache> caches = new ArrayList<>();
	for (String cacheName : cacheNames) {
		caches.add(new ConcurrentMapCache(cacheName));
	}
	result.setCaches(caches);
	result.afterPropertiesSet();
	return result;
}
 
Example 7
Source Project: spring-analysis-note   Source File: JCacheJavaConfigTests.java    License: MIT License 5 votes vote down vote up
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager cm = new SimpleCacheManager();
	cm.setCaches(Arrays.asList(
			defaultCache(),
			new ConcurrentMapCache("primary"),
			new ConcurrentMapCache("secondary"),
			new ConcurrentMapCache("exception")));
	return cm;
}
 
Example 8
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager cm = new SimpleCacheManager();
	cm.setCaches(Arrays.asList(
			defaultCache(),
			exceptionCache()));
	return cm;
}
 
Example 9
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager cm = new SimpleCacheManager();
	cm.setCaches(Arrays.asList(
			defaultCache(),
			new ConcurrentMapCache("primary"),
			new ConcurrentMapCache("secondary"),
			new ConcurrentMapCache("exception")));
	return cm;
}
 
Example 10
Source Project: java-technology-stack   Source File: CacheTestUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Create a {@link SimpleCacheManager} with the specified cache(s).
 * @param cacheNames the names of the caches to create
 */
public static CacheManager createSimpleCacheManager(String... cacheNames) {
	SimpleCacheManager result = new SimpleCacheManager();
	List<Cache> caches = new ArrayList<>();
	for (String cacheName : cacheNames) {
		caches.add(new ConcurrentMapCache(cacheName));
	}
	result.setCaches(caches);
	result.afterPropertiesSet();
	return result;
}
 
Example 11
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager mgr = new SimpleCacheManager();
	ArrayList<Cache> caches = new ArrayList<>();
	caches.add(new ConcurrentMapCache(""));
	mgr.setCaches(caches);
	return mgr;
}
 
Example 12
Source Project: java-technology-stack   Source File: AbstractJCacheTests.java    License: MIT License 5 votes vote down vote up
protected static CacheManager createSimpleCacheManager(String... cacheNames) {
	SimpleCacheManager result = new SimpleCacheManager();
	List<Cache> caches = new ArrayList<>();
	for (String cacheName : cacheNames) {
		caches.add(new ConcurrentMapCache(cacheName));
	}
	result.setCaches(caches);
	result.afterPropertiesSet();
	return result;
}
 
Example 13
Source Project: java-technology-stack   Source File: JCacheJavaConfigTests.java    License: MIT License 5 votes vote down vote up
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager cm = new SimpleCacheManager();
	cm.setCaches(Arrays.asList(
			defaultCache(),
			new ConcurrentMapCache("primary"),
			new ConcurrentMapCache("secondary"),
			new ConcurrentMapCache("exception")));
	return cm;
}
 
Example 14
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager cm = new SimpleCacheManager();
	cm.setCaches(Arrays.asList(
			defaultCache(),
			exceptionCache()));
	return cm;
}
 
Example 15
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager cm = new SimpleCacheManager();
	cm.setCaches(Arrays.asList(
			defaultCache(),
			new ConcurrentMapCache("primary"),
			new ConcurrentMapCache("secondary"),
			new ConcurrentMapCache("exception")));
	return cm;
}
 
Example 16
/**
  * The cache manager Bean, that defines caching parameters
  *
  * @param ticker The Ticker handle that Spring passes, unused so far
  * @return the cache manager
  */
 @Bean
 public CacheManager cacheManager(Ticker ticker) {
     SimpleCacheManager manager = new SimpleCacheManager();
     if (specs != null) {
         //@formatter:off
List<CaffeineCache> caches =
		specs.entrySet().stream()
			.map(entry -> buildCache(entry.getKey(), entry.getValue(), ticker))
			.collect(Collectors.toList());
//@formatter:on
         manager.setCaches(caches);
     }
     return manager;
 }
 
Example 17
Source Project: Groza   Source File: CaffeineCacheConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager cacheManager() {
    SimpleCacheManager manager = new SimpleCacheManager();
    if (specs != null) {
        List<CaffeineCache> caches =
                specs.entrySet().stream()
                .map(entry -> buildCache(entry.getKey(),
                        entry.getValue()))
                .collect(Collectors.toList());
        manager.setCaches(caches);
    }
    return manager;
}
 
Example 18
Source Project: microservices-sample-project   Source File: CacheConfig.java    License: Apache License 2.0 5 votes vote down vote up
public static CacheManager createCacheManager(String... caches) {
List<ConcurrentMapCache> concurrentMapCaches = new ArrayList<>();
for(String cacheName : caches){
	concurrentMapCaches.add(new ConcurrentMapCache(cacheName));
	concurrentMapCaches.add(new ConcurrentMapCache(cacheName + CONCAT + SUFFIX));
}

      SimpleCacheManager cacheManager = new SimpleCacheManager();
      cacheManager.setCaches(concurrentMapCaches);
      return cacheManager;
  }
 
Example 19
Source Project: spring4-understanding   Source File: CacheTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a {@link SimpleCacheManager} with the specified cache(s).
 * @param cacheNames the names of the caches to create
 */
public static CacheManager createSimpleCacheManager(String... cacheNames) {
	SimpleCacheManager result = new SimpleCacheManager();
	List<Cache> caches = new ArrayList<Cache>();
	for (String cacheName : cacheNames) {
		caches.add(new ConcurrentMapCache(cacheName));
	}
	result.setCaches(caches);
	result.afterPropertiesSet();
	return result;
}
 
Example 20
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager mgr = new SimpleCacheManager();
	ArrayList<Cache> caches = new ArrayList<Cache>();
	caches.add(new ConcurrentMapCache(""));
	mgr.setCaches(caches);
	return mgr;
}
 
Example 21
Source Project: spring4-understanding   Source File: AbstractJCacheTests.java    License: Apache License 2.0 5 votes vote down vote up
protected static CacheManager createSimpleCacheManager(String... cacheNames) {
	SimpleCacheManager result = new SimpleCacheManager();
	List<Cache> caches = new ArrayList<Cache>();
	for (String cacheName : cacheNames) {
		caches.add(new ConcurrentMapCache(cacheName));
	}
	result.setCaches(caches);
	result.afterPropertiesSet();
	return result;
}
 
Example 22
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager cm = new SimpleCacheManager();
	cm.setCaches(Arrays.asList(
			defaultCache(),
			new ConcurrentMapCache("primary"),
			new ConcurrentMapCache("secondary"),
			new ConcurrentMapCache("exception")));
	return cm;
}
 
Example 23
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager cm = new SimpleCacheManager();
	cm.setCaches(Arrays.asList(
			defaultCache(),
			exceptionCache()));
	return cm;
}
 
Example 24
@Bean
public CacheManager cacheManager() {
	SimpleCacheManager cm = new SimpleCacheManager();
	cm.setCaches(Arrays.asList(
			defaultCache(),
			new ConcurrentMapCache("primary"),
			new ConcurrentMapCache("secondary"),
			new ConcurrentMapCache("exception")));
	return cm;
}
 
Example 25
Source Project: mojito   Source File: CachingConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@Override
public CacheManager cacheManager() {
    Cache defaultCache = new ConcurrentMapCache("default");
    Cache localesCache = new ConcurrentMapCache("locales");
    Cache pluralForm = new ConcurrentMapCache("pluralForms");

    SimpleCacheManager manager = new SimpleCacheManager();
    manager.setCaches(Arrays.asList(defaultCache, localesCache, pluralForm));

    return manager;
}
 
Example 26
/**
 * 个性化配置缓存
 */
@Bean
public CacheManager cacheManager() {
    SimpleCacheManager manager = new SimpleCacheManager();
    //把各个cache注册到cacheManager中,GuavaCache实现了org.springframework.cache.Cache接口
    ArrayList<GuavaCache> caches = new ArrayList<>();
    for (Caches c : Caches.values()) {
        caches.add(new GuavaCache(c.name(), CacheBuilder.newBuilder().recordStats().expireAfterWrite(c.getTtl(), TimeUnit.SECONDS).maximumSize(c.getMaxSize()).build()));
    }
    manager.setCaches(caches);
    return manager;
}
 
Example 27
@Override
public CacheManager cacheManager() {
	List<Cache> caches = new ArrayList<>(this.cacheNames.size());
	for (String cacheName : this.cacheNames) {
		caches.add(clusterCache(cacheName));
	}

	SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
	simpleCacheManager.setCaches(caches);
	simpleCacheManager.afterPropertiesSet();
	return simpleCacheManager;
}
 
Example 28
Source Project: aws-refapp   Source File: ReferenceApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager createSimpleCacheManager() {
    SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
    List<Cache> caches = new ArrayList<>(2);
    caches.add(new ConcurrentMapCache("CacheCluster"));
    caches.add(new ConcurrentMapCache("GitHubSourceCode"));
    simpleCacheManager.setCaches(caches);

    return simpleCacheManager;
}
 
Example 29
Source Project: cloudbreak   Source File: CachingConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager cacheManager() {
    SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
    Set<Cache> caches = cacheDefinitions.stream().map(CacheDefinition::cacheConfiguration).collect(Collectors.toSet());
    simpleCacheManager.setCaches(caches);
    return simpleCacheManager;
}
 
Example 30
Source Project: cloudbreak   Source File: CachingConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager cacheManager() {
    SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
    Set<Cache> caches = cacheDefinitions.stream().map(CacheDefinition::cacheConfiguration).collect(Collectors.toSet());
    simpleCacheManager.setCaches(caches);
    simpleCacheManager.initializeCaches();
    return simpleCacheManager;
}