T
- The type of cache.public abstract class FileBasedCache<T> extends Object
Modifier and Type | Field and Description |
---|---|
protected File |
cacheDir
Cache directory.
|
Constructor and Description |
---|
FileBasedCache(String cacheName)
Creates a new FileBasedCache object.
|
Modifier and Type | Method and Description |
---|---|
T |
cache(T id)
Ensure that a file containing the appropriate content exists for the ID.
|
protected abstract T |
cacheData(T id)
Fill in actual data in the file in the cache.
|
Map<T,File> |
get(Set<T> ids)
Utility method to get a number of cache entries at a time.
|
File |
getCacheDir()
Get the directory that the files are cached in.
|
abstract File |
getCacheFile(T id)
Get the file that caches content for the given ID.
|
Index<T> |
getIndex(T id)
Forgiving index generating method, that returns a file with an index, of the greatest possible subset of a given
id, and the subset.
|
public FileBasedCache(String cacheName)
cacheName
- Name of this cache (enabling sharing among processes). The directory created in the cachedir
will have this name.public File getCacheDir()
public abstract File getCacheFile(T id)
id
- Some sort of id that uniquely identifies the item within the cache.protected abstract T cacheData(T id)
id
- Some identifier for the item to be cached.public T cache(T id)
Locking: If the file is not immediately found, we enter a file-creation state. To avoid corrupted data, we must ensure that only one cache instance, and only one thread within any instance, creates the file. Thus as long as somebody else seems to be creating the file, we wait and see if they finish. This is checked by having an exclusive lock on a ".working" file (we cannot use the result file, as it has to be created to be locked, and we may end up with a different cached file than we thought, see above). The .working file itself is irrelevant, only the lock on it matters.
id
- Some sort of id that uniquely identifies the item within the cache.public Map<T,File> get(Set<T> ids)
ids
- List of IDs that uniquely identify a set of items within the cache.public Index<T> getIndex(T id)
If the type I for instance is a Set, you may get an index of only a subset. If I is a File, null may be seen as a subset.
id
- The requested index.for more information.
Copyright © 2005–2016 The Royal Danish Library, the Danish State and University Library, the National Library of France and the Austrian National Library.. All rights reserved.