cache

作者: yehongyu_2018 | 来源:发表于2019-01-09 18:04 被阅读0次

guava cache的使用

package co.yhy.cache;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import java.util.concurrent.TimeUnit;
public class PayloadCache {
    private static final long EXPIRE_TIME_AFTER_WRITE = 60;
    private static final long CACHE_LIMIT_SIZE = 2000;
    private static volatile PayloadCache instance;
    private Cache<String, String> cache;

    private PayloadCache() {
        this.cache = CacheBuilder.newBuilder()
                .expireAfterWrite(EXPIRE_TIME_AFTER_WRITE, TimeUnit.SECONDS)
                .maximumSize(CACHE_LIMIT_SIZE)
                .build();
        DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);
    }

    public static MessagePayloadCache getInstance() {
        if (instance == null) {
            synchronized (MessagePayloadCache.class) {
                if (instance == null) {
                    instance = new MessagePayloadCache();
                }
            }
        }
        return instance;
    }
    public void put(String key, String value) {
        cache.put(key, value);
    }
    public String get(String key) {
        return cache.get(key);
    }
}

相关文章

  • cache缓存

    -(NSCache *)cache { if (_cache == nil) { _cache = [[NSCac...

  • apache geode docs

    Apache Cache Docs [Apache Cache Docs](# Apache Cache Docs...

  • 清空npm 缓存

    npm cache verify npm cache clean npm cache clean --force ...

  • cache_t结构探一探

    接上文类的结构分析 一.cache_t结构 1.cache_t结构 cache是cache_t类型,那么cache...

  • Invalid response body while tryi

    该报错解决办法: npm cache verifynpm cache cleannpm cache clean -...

  • python: flask的动态cache

    cache.set()以及cache.get()的使用 flask的cache功能十分强大,所谓的动态cache,...

  • HTTP首部(二)

    Cache-Control扩展 cache-extension token Cache-Control: priv...

  • Redis-Spring Cache

    零、本文纲要 一、Spring Cache介绍 Spring Cache Spring Cache常用注解 二、 ...

  • RocksDB. LRUCache源码分析

    Block Cache RocksDB使用Block cache作为读cache。用户可以指定Block cach...

  • LRU Cache

    之前面试被问到了LRU Cache,之前没接触,现在学习补充一下。 什么是Cache Cache概念 Cache,...

网友评论

      本文标题:cache

      本文链接:https://www.haomeiwen.com/subject/dkwgrqtx.html