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

com.feingto.cloud.cache.provider.DefaultCacheProvider Maven / Gradle / Ivy

package com.feingto.cloud.cache.provider;

import com.feingto.cloud.cache.ICache;
import com.google.common.collect.Maps;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * 系统缓存
 *
 * @author longfei
 */
@SuppressWarnings("unchecked")
public class DefaultCacheProvider implements ICache {
    private Map data = Maps.newHashMap();

    @Override
    public  T get(String key) {
        return (T) this.data.get(key);
    }

    @Override
    public void put(String key, Object value) {
        this.data.put(key, value);
    }

    @Override
    public void put(String key, Object obj, long expireTime) {
        data.put(key, obj);
    }

    @Override
    public boolean has(String key) {
        return this.data.containsKey(key);
    }

    @Override
    public void remove(String key) {
        this.data.remove(key);
    }

    @Override
    public void removeByPrefix(String prefix) {
        Set keys = this.keys();
        Set removeKeys = new HashSet<>();
        for (String key : keys) {
            if (key.startsWith(prefix)) {
                removeKeys.add(key);
            }
        }

        //删除
        for (String k : removeKeys) {
            remove(k);
        }
    }

    @Override
    public void clear() {
        this.data.clear();
    }

    @Override
    public Set keys() {
        return data.keySet();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy