Package com.globalmentor.cache
Interface Cache<Q,V>
- Type Parameters:
Q
- The type of query used to request data from the cache.V
- The type of value stored in the cache.
- All Known Implementing Classes:
AbstractCache
,AbstractFileCache
public interface Cache<Q,V>
A cache that can fetch information when needed.
A cached value is retrieved using a query. The value is stored in the cache as part of the cache data.
- Author:
- Garret Wilson
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
Class for storing a value along with its expiration information and other information. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCacheFetchListener
(Q key, CacheFetchListener<Q, V> listener) Adds a listener to listen for a value being fetched.Retrieves a value from the cache.Retrieves a value from the cache.Retrieves data from the cache.Retrieves data from the cache.long
boolean
Determined if a non-stale value is in the cache.boolean
void
removeCacheFetchListener
(Q key, CacheFetchListener<Q, V> listener) Removes a listener to listen for a value being fetched.void
setExpiration
(long expiration) Sets the life of an object in the cache.void
setFetchSynchronous
(boolean fetchSynchronous) Sets whether fetching new values is synchronous.Removes a value from the cache.
-
Method Details
-
isFetchSynchronous
boolean isFetchSynchronous()- Returns:
- Whether fetching new values is synchronous.
-
setFetchSynchronous
void setFetchSynchronous(boolean fetchSynchronous) Sets whether fetching new values is synchronous. Changing this value does not change the sychronicity of fetches that have already started but have not yet completed.- Parameters:
fetchSynchronous
- Whether fetches for new values should occur synchronously.
-
getExpiration
long getExpiration()- Returns:
- The life of an object in the cache, in milliseconds.
-
setExpiration
void setExpiration(long expiration) Sets the life of an object in the cache.- Parameters:
expiration
- The length of time, in milliseconds, to keep cached information.
-
addCacheFetchListener
Adds a listener to listen for a value being fetched.- Parameters:
key
- The query for requesting a value from the cache.listener
- The listener to be notified when the value is fetched.
-
removeCacheFetchListener
Removes a listener to listen for a value being fetched.- Parameters:
key
- The query for requesting a value from the cache.listener
- The listener to be notified when the value is fetched.
-
isCached
Determined if a non-stale value is in the cache.- Parameters:
query
- The query for requesting a value from the cache.- Returns:
- Whether the value associated with the given query is in the cache and not stale.
- Throws:
IOException
- if there was an error checking the cached information for staleness.
-
get
Retrieves a value from the cache. Values are fetched from the backing store if needed, and this method blocks until the data is fetched.- Parameters:
query
- The query for requesting a value from the cache.- Returns:
- The cached value.
- Throws:
IOException
- if there was an error fetching the value from the backing store.
-
get
Retrieves a value from the cache. Values are fetched from the backing store if needed, with fetching optionally deferred until later.- Parameters:
query
- The query for requesting a value from the cache.deferFetch
- Whether fetching, if needed, should be deffered and performed in an asynchronous thread.- Returns:
- The cached value, or
null
if fetching was deferred. - Throws:
IOException
- if there was an error fetching the value from the backing store.
-
getData
Retrieves data from the cache. Data is fetched from the backing store if needed, and this method blocks until the data is fetched.- Parameters:
query
- The query for requesting data from the cache.- Returns:
- The cached data.
- Throws:
IOException
- if there was an error fetching the data from the backing store.
-
getData
Retrieves data from the cache. Data is fetched from the backing store if needed, with fetching optionally deferred until later.- Parameters:
query
- The query for requesting data from the cache.deferFetch
- Whether fetching, if needed, should be deffered and performed in an asynchronous thread.- Returns:
- The cached data, or
null
if fetching was deferred. - Throws:
IOException
- if there was an error fetching the value from the backing store.
-
uncache
Removes a value from the cache.- Parameters:
query
- The query for requesting a value from the cache.- Returns:
- The previously cached value, even if stale, or
null
if there was no cached value. - Throws:
IOException
- if there was an error removing the value from the cache.
-