All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cattleframework.utils.cache.caffeine.CaffeineCacheManager Maven / Gradle / Ivy

There is a newer version: 1.0.1-M3
Show newest version
/*
 * Copyright (C) 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.cattleframework.utils.cache.caffeine;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.cattleframework.exception.CattleException;
import org.cattleframework.utils.cache.AbstractCacheManager;
import org.cattleframework.utils.cache.Cache;
import org.cattleframework.utils.cache.CacheConstants;

import com.github.benmanes.caffeine.cache.Caffeine;

/**
 * Caffeine缓存管理器
 * 
 * @author orange
 *
 */
public class CaffeineCacheManager extends AbstractCacheManager {

    @Override
    protected Cache createCache(String name, Map props) {
	String spec = props.get(CacheConstants.CACHE_CAFFEINE);
	if (StringUtils.isBlank(spec)) {
	    throw new CattleException("Caffeine缓存分类'" + name + "'的Spec为空");
	}
	return new CaffeineCache(Caffeine.from(spec).build());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy