| Modifier and Type | Field and Description |
|---|---|
| private final ReadWriteLock | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public V | |
| protected abstract V | Returns: The resulting value.Key value for which a value must be computed. key)Must be implemented in a subclass. |
| public V | Returns: value from the cache, or null if none.Key to value that may be in cache. key)Remove any value associated with the key. |
| lock | back to summary |
|---|---|
| private final ReadWriteLock lock | |
| map | back to summary |
|---|---|
| private final Map<K, V> map | |
| WeakCache | back to summary |
|---|---|
| public WeakCache() | |
| clear | back to summary |
|---|---|
| public void clear() Remove all entries from the cache. | |
| get | back to summary |
|---|---|
| public V get(K key) Return the value (if any) associated with key. If the value is already in the cache, only a read lock is held, so many threads can concurrently call get. If no value is in the cache corresponding to key, a new value will be computed and cached, in which case a write lock is held long enough to update the map. Note that the write lock is NOT held while the value is computed by calling the lookup method. Because of this, it is possible for redundant computation to occur when two or more thread concurrently call get on the same key which is not (yet) in the cache.
| |
| lookup | back to summary |
|---|---|
| protected abstract V lookup(K key) Must be implemented in a subclass. Must compute a value corresponding to a key. The computation may be fairly expensive. Note that no lock is held during this computation.
| |
| remove | back to summary |
|---|---|
| public V remove(K key) Remove any value associated with the key.
| |