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

io.github.ye17186.myhelper.caffeine.cache.CaffeineCacheManager Maven / Gradle / Ivy

There is a newer version: 0.0.6
Show newest version
package io.github.ye17186.myhelper.caffeine.cache;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import io.github.ye17186.myhelper.caffeine.autoconfigure.properties.CaffeineCacheProperties;
import org.springframework.lang.NonNull;

import java.util.concurrent.TimeUnit;

/**
 * 自定义Caffeine缓存管理器
 *
 * @author ye17186
 * @since 2022-11-07
 */
public class CaffeineCacheManager extends org.springframework.cache.caffeine.CaffeineCacheManager {

    private final CaffeineCacheProperties properties;

    public CaffeineCacheManager(CaffeineCacheProperties properties) {

        this.properties = properties;
    }

    @Override
    @NonNull
    protected Cache createNativeCaffeineCache(@NonNull String name) {

        Long timeout = properties.getCacheSpecs().get(name);
        if (timeout == null) {
            timeout = properties.getTimeout();
        }

        final Caffeine caffeine = Caffeine.newBuilder()
                .expireAfterWrite(timeout, TimeUnit.SECONDS);
        return caffeine.build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy