com.github.pojomvcc.CacheExpiry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pojo-mvcc Show documentation
Show all versions of pojo-mvcc Show documentation
A simple in-memory POJO Multi Version Concurrency Control (MVCC) cache.
The newest version!
package com.github.pojomvcc;
/**
* A {@code CacheExpiry} dictates how long revision history (tracked as a {@link CacheElementRevision})
* should be kept in the {@code com.github.pojomvcc.RootObjectCache}. Once the {@link CacheExpiryPolicy}
* has determined that a {@link CacheElementRevision} should no longer be kept an optional
* {@code com.github.pojomvcc.CacheExpirationHandler} can be used to keep the {@link CacheElementRevision}
* somewhere else.
*
* @author Aidan Morgan
*/
public class CacheExpiry {
/**
* The default {@link CacheExpiry} to use
*/
public static CacheExpiry DEFAULT() {
return new CacheExpiry(CacheExpiryPolicy.NO_LONGER_USED());
}
/**
* The {@link CacheExpiryPolicy} to use.
*/
private CacheExpiryPolicy policy;
/**
* The {@link CacheExpirationHandler} to use, defaults to {@link CacheExpiry.NoOpCacheExpirationHandler}.
*/
private CacheExpirationHandler handler = new NoOpCacheExpirationHandler();
/**
* Creates a new {@link CacheExpiry} with a no-op {@link CacheExpirationHandler}
* handler.
*
* @param policy The cache expiration policy.
*/
public CacheExpiry(CacheExpiryPolicy policy) {
this.policy = policy;
}
/**
* Creates a new {@link CacheExpiry} with the provided {@link CacheExpiryPolicy}
* and the provided {@link CacheExpirationHandler}.
*
* @param policy The cache expiration policy.
* @param handler The expiration handler.
*/
public CacheExpiry(CacheExpiryPolicy policy, CacheExpirationHandler handler) {
this.policy = policy;
this.handler = handler;
}
/**
* Returns the cache's expiration policy.
*
* @return The expiration policy.
*/
public CacheExpiryPolicy getPolicy() {
return policy;
}
/**
* Returns the cache's expiration handler.
*
* @return The cache's expiration handler.
*/
public CacheExpirationHandler getHandler() {
return handler;
}
/**
* A no-op implementation of {@link CacheExpirationHandler}.
*/
private static class NoOpCacheExpirationHandler implements CacheExpirationHandler {
public void expired(RevisionKeyList rev) {
// No-op
}
public CacheElementRevision retrieve(K key, long revision) {
return null; // No-op
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy