public interface ObjectCache
try
... finally
block.
To use as a reader:
To overwrite:key = "EPSG:4326"; CoordinateReferenceSystem crs = cache.get(key);
To reserve the entry while figuring out what to write:cache.put(key, crs);
To use as a proper cache:try { cache.writeLock(key); // may block if another writer is working on this code. value = cache.peek(key); if (value == null) { // another writer got here first } else { value = figuringOutWhatToWrite(....); cache.put(key, value); } } finally { cache.writeUnLock(key); }
CylindricalCS cs = (CylindricalCS) cache.get(key); if (cs == null) { try { cache.writeLock(key); cs = (CylindricalCS) cache.test(key); if (cs == null) { cs = csAuthority.createCylindricalCS(code); cache.put(key, cs); } } finally { cache.writeUnLock(key); } } return cs;
https://jsr-107-interest.dev.java.net/javadoc/javax/cache/package-summary.html
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all entries from this cache.
|
Object |
get(Object key)
Returns an object from the pool for the specified code.
|
Set<Object> |
getKeys()
Returns a set of all the keys currently contained within the ObjectCache.
|
Object |
peek(Object key)
Use the write lock to test the value for the provided key.
|
void |
put(Object key,
Object object)
Puts an element into the cache.
|
void |
remove(Object key)
Removes a given key from the cache.
|
void |
writeLock(Object key)
Acquire a write lock on the indicated key.
|
void |
writeUnLock(Object key)
Release write lock on the indicated key.
|
void clear()
Object get(Object key)
referent
is returned.key
- The key whose associated value is to be returned.Object peek(Object key)
This method is used by a writer to test if someone (ie another writer) has provided the value for us (while we were blocked waiting for them).
key
- null
void put(Object key, Object object)
You may simply use this method - it is threadsafe:
cache.put("4326", crs);You may also consider reserving the entry while you work on the answer:
try { cache.writeLock( "fred" ); ...find fred cache.put( "fred", fred ); } finally { cache.writeUnLock(); }
key
- the authority code.object
- The referencing object to add in the pool.void writeLock(Object key)
key
- void writeUnLock(Object key)
key
- Set<Object> getKeys()
This is a static copy of the keys in the cache at the point in time when the function is called.
void remove(Object key)
key
- Copyright © 1996–2019 Geotools. All rights reserved.