package com.cyksj.common.annotation;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @author zwhui
 * @date 2020/7/16 上午11:07
 */

@Configuration
public class UrlCache {
    @Bean
    public Cache<String, Integer> getCache() {
        return CacheBuilder.newBuilder().expireAfterWrite(2L, TimeUnit.SECONDS).build();// 缓存有效期为2秒
    }

    @Bean("recordCache")
    public Cache<String, String> recordCache() {
        return CacheBuilder.newBuilder().expireAfterWrite(30L, TimeUnit.SECONDS).build();// 缓存有效期为30秒
    }

    @Bean("countCache")
    public Cache<String, String> countCache() {
        return CacheBuilder.newBuilder().expireAfterWrite(600L, TimeUnit.SECONDS).build();// 缓存有效期为600秒
    }

}
