package com.r35157.libs.objcache.impl.ref;

import java.util.Objects;

public final class ObjectCacheEntry {

    public ObjectCacheEntry(
            Object object,
            long insertedAtMillis,
            long ttlMillis
    ) {
        this.object = Objects.requireNonNull(object);
        this.insertedAtMillis = insertedAtMillis;
        this.ttlMillis = ttlMillis;
    }

    public Object getObject() {
        return object;
    }

    public long getAgeMillis() {
        return System.currentTimeMillis() - insertedAtMillis;
    }

    public boolean isExpired() {
        return getAgeMillis() >= ttlMillis;
    }

    private final Object object;
    private final long insertedAtMillis;
    private final long ttlMillis;
}