private static final String CLI_CACHE = "users";
private SessionsManager() {
- CacheManager cm = CacheManager.newInstance();
- authUsers = new Cache(new CacheConfiguration(CLI_CACHE, MAX_CACHED_USERS_IN_MEMORY)
- .maxEntriesLocalDisk(MAX_CACHED_USERS_ON_DISK).timeToLiveSeconds(SECONDS_TO_LIVE)
- .timeToIdleSeconds(SECONDS_TO_IDLE));
- cm.addCache(authUsers);
- cm.setName(CLI_CACHE_MANAGER);
+ // When we restart, the cache manager and CLI cache are already there
+ CacheManager cm = CacheManager.getCacheManager(CLI_CACHE_MANAGER);
+ if (cm == null) {
+ cm = CacheManager.newInstance();
+ cm.setName(CLI_CACHE_MANAGER);
+ }
+ Cache existingCache = cm.getCache(CLI_CACHE);
+ if (existingCache != null) {
+ authUsers = existingCache;
+ } else {
+ authUsers = new Cache(new CacheConfiguration(CLI_CACHE, MAX_CACHED_USERS_IN_MEMORY)
+ .maxEntriesLocalDisk(MAX_CACHED_USERS_ON_DISK).timeToLiveSeconds(SECONDS_TO_LIVE)
+ .timeToIdleSeconds(SECONDS_TO_IDLE));
+ cm.addCache(authUsers);
+ }
LOG.info("Initialized cli authorized users cache manager");
}
}
@Override
- public void close() throws Exception {
+ public void close() {
LOG.info("Shutting down cli authorized users cache manager");
CacheManager.getInstance().shutdown();
}
private final Cache tokens;
public H2TokenStore(long secondsToLive, long secondsToIdle) {
- CacheManager cm = CacheManager.newInstance();
- tokens = new Cache(new CacheConfiguration(TOKEN_CACHE, maxCachedTokensInMemory)
- .maxEntriesLocalDisk(maxCachedTokensOnDisk)
- .timeToLiveSeconds(secondsToLive)
- .timeToIdleSeconds(secondsToIdle));
- cm.addCache(tokens);
- cm.setName(TOKEN_CACHE_MANAGER);
+ // When we restart, the cache manager and token cache are already there
+ CacheManager cm = CacheManager.getCacheManager(TOKEN_CACHE_MANAGER);
+ if (cm == null) {
+ cm = CacheManager.newInstance();
+ cm.setName(TOKEN_CACHE_MANAGER);
+ }
+ Cache existingCache = cm.getCache(TOKEN_CACHE);
+ if (existingCache != null) {
+ tokens = existingCache;
+ } else {
+ tokens = new Cache(new CacheConfiguration(TOKEN_CACHE, maxCachedTokensInMemory)
+ .maxEntriesLocalDisk(maxCachedTokensOnDisk)
+ .timeToLiveSeconds(secondsToLive)
+ .timeToIdleSeconds(secondsToIdle));
+ cm.addCache(tokens);
+ }
LOG.info("Initialized token store with default cache config");
}
@Override
- public void close() throws Exception {
+ public void close() {
LOG.info("Shutting down token store...");
CacheManager.getInstance().shutdown();
}