Initalizing Cache library

This commit is contained in:
Andrew Shvayka 2018-07-18 14:50:36 +03:00
parent e9d7561fd8
commit a983316e64

View File

@ -1,12 +1,12 @@
/** /**
* Copyright © 2016-2018 The Thingsboard Authors * Copyright © 2016-2018 The Thingsboard Authors
* * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,8 +16,10 @@
package org.thingsboard.server.dao.cache; package org.thingsboard.server.dao.cache;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalCause;
import com.github.benmanes.caffeine.cache.Ticker; import com.github.benmanes.caffeine.cache.Ticker;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
@ -28,6 +30,7 @@ import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -38,12 +41,14 @@ import java.util.stream.Collectors;
@ConfigurationProperties(prefix = "caffeine") @ConfigurationProperties(prefix = "caffeine")
@EnableCaching @EnableCaching
@Data @Data
@Slf4j
public class CaffeineCacheConfiguration { public class CaffeineCacheConfiguration {
private Map<String, CacheSpecs> specs; private Map<String, CacheSpecs> specs;
@Bean @Bean
public CacheManager cacheManager() { public CacheManager cacheManager() {
log.trace("Initializing cache: {}", Arrays.toString(RemovalCause.values()));
SimpleCacheManager manager = new SimpleCacheManager(); SimpleCacheManager manager = new SimpleCacheManager();
if (specs != null) { if (specs != null) {
List<CaffeineCache> caches = List<CaffeineCache> caches =