argos/dmp-backend/web/src/main/java/eu/eudat/cache/ResponsesCache.java

43 lines
1.8 KiB
Java
Raw Normal View History

2017-12-15 00:01:26 +01:00
package eu.eudat.cache;
2018-02-16 11:34:02 +01:00
import com.google.common.cache.CacheBuilder;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
2018-02-16 11:34:02 +01:00
import org.springframework.cache.guava.GuavaCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
2018-02-16 11:34:02 +01:00
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Component
@EnableCaching
public class ResponsesCache {
2018-02-16 11:34:02 +01:00
public static long HOW_MANY = 30;
public static TimeUnit TIME_UNIT = TimeUnit.MINUTES;
@Bean
public CacheManager cacheManager() {
System.out.print("Loading ResponsesCache...");
SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
List<GuavaCache> caches = new ArrayList<GuavaCache>();
caches.add(new GuavaCache("repositories", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new GuavaCache("projects", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new GuavaCache("organisations", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new GuavaCache("registries", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
caches.add(new GuavaCache("services", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
2018-07-11 15:47:36 +02:00
caches.add(new GuavaCache("tags", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
2018-02-16 11:34:02 +01:00
caches.add(new GuavaCache("researchers", CacheBuilder.newBuilder().expireAfterAccess(HOW_MANY, TIME_UNIT).build()));
simpleCacheManager.setCaches(caches);
System.out.println("OK");
return simpleCacheManager;
}
}