package com.bawei.cache;

import com.bawei.common.core.utils.thread.ThreadPool;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author DongZl
 * @description: 缓存基准
 * @Date 2022-10-18 下午 02:57
 */
public interface BaseCache<K, V> {

    public static final long time = 2;

    @Autowired
    public ThreadPool threadPool = null;

    /**
     * 获取Redis的key 用来 对缓存进行操作
     * @param key 数据Id
     * @return
     */
    public String getKey(K key);

    /**
     * 增/改
     * @param key 键
     * @param val 值
     * @return
     */
    public boolean put(K key, V val);

    /**
     * 删
     * @param key 键
     * @return
     */
    public boolean remove(K key);

    /**
     * 延迟删
     * @param key 键
     */
    public default void delayRemove(K key){
        ThreadPool.getThreadPool().delayExecute(time, new Runnable() {
            @Override
            public void run () {
                remove(key);
            }
        });
    }


    /**
     * 查
     * @param key 键
     * @return val 值
     */
    public V get(K key);

}
