123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package com.primeton.damp.cache;
- import com.google.common.cache.Cache;
- import com.google.common.cache.CacheBuilder;
- /**
- * <pre>
- *
- * Created by zhenqin.
- * User: zhenqin
- * Date: 2021/4/2
- * Time: 11:15
- * Vendor: yiidata.com
- * To change this template use File | Settings | File Templates.
- *
- * </pre>
- *
- * @author zhenqin
- */
- public class GuavaMemCached implements ICache<Object> {
- /**
- * 缓存实现
- */
- final Cache<String, Object> cached = CacheBuilder.newBuilder().maximumSize(10000).initialCapacity(500).build();
- public GuavaMemCached() {
- }
- @Override
- public void add(String key, Object value) {
- cached.put(key, value);
- }
- @Override
- public void add(String key, int exp, Object value) {
- cached.put(key, value);
- }
- @Override
- public Object get(String key) {
- return cached.getIfPresent(key);
- }
- @Override
- public Object remove(String key) {
- cached.invalidate(key);
- return null;
- }
- @Override
- public int removeByPrefix(String prefix) {
- return 0;
- }
- @Override
- public void clear() {
- cached.cleanUp();
- }
- @Override
- public int size() {
- return (int)cached.size();
- }
- @Override
- public void shutdown() {
- clear();
- }
- }
|