net.sf.ehcache.Cache backed cache that creates entries on demand.
Clients of the cache simply call it without needing knowledge of whether the entry exists in the cache, or whether it needs updating before use.
Thread safety depends on the factory being used. The UpdatingCacheEntryFactory should be made thread safe. In addition users of returned values should not modify their contents.
| Modifier and Type | Field and Description |
|---|---|
| private static final Logger |
| Access | Constructor and Description |
|---|---|
| public | UpdatingSelfPopulatingCache(Ehcache cache, final UpdatingCacheEntryFactory factory)
Creates a SelfPopulatingCache. |
| Modifier and Type | Method and Description |
|---|---|
| public Element | Returns: a valueOverrides net. Implements net. |
| public void | refresh()
Overrides net. |
| protected void |
| LOG | back to summary |
|---|---|
| private static final Logger LOG Hides net. | |
| UpdatingSelfPopulatingCache | back to summary |
|---|---|
| public UpdatingSelfPopulatingCache(Ehcache cache, final UpdatingCacheEntryFactory factory) throws CacheException Creates a SelfPopulatingCache. | |
| get | back to summary |
|---|---|
| public Element get(final Object key) throws LockTimeoutException Overrides net. Implements net. Looks up an object.
If null, it creates it. If not null, it updates it. For performance this method should only be
used with It is expected that gets, which update as part of the get, might take considerable time. Access to the cache cannot be blocked while that is happening. This method is therefore not synchronized. Sync's are used for thread safety based on key
| |
| refresh | back to summary |
|---|---|
| public void refresh() throws CacheException Overrides net. This method should not be used. Because elements are always updated before they are returned, it makes no sense to refresh this cache. | |
| update | back to summary |
|---|---|
| protected void update(final Object key) Element can never be null. Add a null guard just in case. | |