package info.frostfs.sdk.pool; import info.frostfs.sdk.dto.session.SessionToken; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; public class SessionCache { private final ConcurrentMap cache = new ConcurrentHashMap<>(); private final long tokenDuration; private long currentEpoch; public SessionCache(long sessionExpirationDuration) { this.tokenDuration = sessionExpirationDuration; } public boolean contains(String key) { return cache.containsKey(key); } public boolean tryGetValue(String key, SessionToken[] value) { if (key == null) { value[0] = null; return false; } SessionToken token = cache.get(key); if (token != null) { value[0] = token; return true; } return false; } public void setValue(String key, SessionToken value) { if (key != null) { cache.put(key, value); } } public void deleteByPrefix(String prefix) { cache.keySet().removeIf(key -> key.startsWith(prefix)); } }