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

work.wangjw.dao.impl.AuthDefaultDao Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package work.wangjw.dao.impl;

import lombok.extern.slf4j.Slf4j;
import work.wangjw.bean.AuthSession;
import work.wangjw.dao.AuthDao;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author Gavin
 * @since 2021/7/21 10:09
 **/
@Slf4j
public class AuthDefaultDao implements AuthDao {

    Map dataMap = new HashMap<>();

    @Override
    public void set(String key, AuthSession value) {
        dataMap.put(key, value);
    }

    @Override
    public AuthSession get(String key) {
        return dataMap.get(key);
    }

    @Override
    public void delete(String key) {
        dataMap.remove(key);
    }

    @Override
    public void clearExpireData() {
        Set keySet = dataMap.keySet();
        for (String key : keySet) {
            AuthSession authSession = get(key);
            Long expireTime = authSession.getExpireTime();
            Long activityExpireTime = authSession.getActivityExpireTime();
            long now = System.currentTimeMillis();
            if ((expireTime != -1L && expireTime < now) || (activityExpireTime != -1L && activityExpireTime < now)) {
                log.info("清除key=" + key);
                delete(key);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy