javax.cache.expiry.EternalExpiryPolicy Maven / Gradle / Ivy
package javax.cache.expiry;
import javax.cache.Cache;
import javax.cache.configuration.Factory;
import javax.cache.configuration.FactoryBuilder;
import java.io.Serializable;
import static javax.cache.expiry.Duration.ETERNAL;
/**
* The eternal {@link ExpiryPolicy} specifies that Cache Entries
* won't expire. This however doesn't mean they won't be expired if an
* underlying implementation needs to free-up resources where by it may
* choose to expire entries that are not due to expire.
*
* @param the type of cache keys
* @param the type of cache values
*/
public final class EternalExpiryPolicy implements ExpiryPolicy, Serializable {
/**
* The serialVersionUID required for {@link java.io.Serializable}.
*/
public static final long serialVersionUID = 201305101603L;
/**
* Obtains a {@link javax.cache.configuration.Factory} for an Eternal {@link ExpiryPolicy}.
*
* @return a {@link javax.cache.configuration.Factory} for an Eternal {@link ExpiryPolicy}.
*/
public static Factory> factoryOf() {
return new FactoryBuilder.SingletonFactory>(new EternalExpiryPolicy());
}
/**
* {@inheritDoc}
*/
@Override
public Duration getExpiryForCreatedEntry(Cache.Entry entry) {
return ETERNAL;
}
/**
* {@inheritDoc}
*/
@Override
public Duration getExpiryForAccessedEntry(Cache.Entry entry) {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public Duration getExpiryForModifiedEntry(Cache.Entry entry) {
return null;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return EternalExpiryPolicy.class.hashCode();
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object other) {
return other instanceof EternalExpiryPolicy;
}
}