public class CacheUtil<K, V> {
    private long DEFAULT_EXPIRATION_TIME = 60L * 1000;

    private Map<K, CacheItem<V>> cacheMap = new HashMap<>();

    public void put(K key, V value) {
        put(key, value, DEFAULT_EXPIRATION_TIME);
    }

    public void put(K key, V value, long expirationTime) {
        long expiration = System.currentTimeMillis() + expirationTime;
        cacheMap.put(key, new CacheItem<V>(value, expiration));
    }

    public V get(K key) {
        CacheItem<V> cacheItem = cacheMap.get(key);
        if (cacheItem == null) {
            return null;
        }
        if (System.currentTimeMillis() > cacheItem.getExpiration()) {
            cacheMap.remove(key);
            return null;
        }
        return cacheItem.getValue();
    }

    public int size() {
        return cacheMap.size();
    }

    private static class CacheItem<V> {
        private V value;
        private long expiration;

        CacheItem(V value, long expiration) {
            this.value = value;
            this.expiration = expiration;
        }

        V getValue() {
            return value;
        }

        long getExpiration() {
            return expiration;
        }
    }
} Include at least 5 hashtags, starting with '#'
user