package com.muyu.carData.config.cacheconfig;
import com.github.benmanes.caffeine.cache.Expiry;
import org.checkerframework.checker.index.qual.NonNegative;

import java.util.concurrent.TimeUnit;

/**
 * @Author：张腾
 * @Package：com.muyu.carData.cacheconfig
 * @Project：cloud-server-8
 * @name：CacheExpiry
 * @Date：2024/9/26 23:46
 */
public class CacheExpiry implements Expiry<String,ExpiryTime>{
    @Override
    public long expireAfterCreate(String key, ExpiryTime value, long currentTime) {
        return TimeUnit.SECONDS.toNanos(value.getExpiryTime());
    }

    @Override
    public long expireAfterUpdate(String key, ExpiryTime value, long currentTime, @NonNegative long currentDuration) {
        return TimeUnit.SECONDS.toNanos(value.getRefreshTime());
    }

    @Override
    public long expireAfterRead(String key, ExpiryTime value, long currentTime, @NonNegative long currentDuration) {
        return TimeUnit.SECONDS.toNanos(value.getRefreshTime());
    }
}
