package ca.recrown.islandsurvivalcraft.caching;

public class CacheValue <ValueType> {
    private volatile ValueType value;
    protected final Identifier identifier;
    private volatile boolean fresh = true;

    public CacheValue(Identifier identifier) {
        this.identifier = identifier;
    }

    public boolean isEmpty() {
        return fresh;
    }

    public synchronized void setValue(ValueType value) {
        this.fresh = false;
        this.value = value;
        identifier.usage ++;
    }

    public ValueType getValue() {
        identifier.usage++;
        return value;
    }
}