Ehcache that creates entries on demand.
Clients of the cache simply call it without needing knowledge of whether the entry exists in the cache.
The cache is designed to be refreshed. Refreshes operate on the backing cache, and do not
degrade performance of get(java. calls.
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 |
|---|---|
| protected final CacheEntryFactory | factory
A factory for creating entries, given a key |
| private static final Logger |
| Access | Constructor and Description |
|---|---|
| public | SelfPopulatingCache(final Ehcache cache, final CacheEntryFactory factory)
Creates a SelfPopulatingCache. |
| public | SelfPopulatingCache(Ehcache cache, int numberOfStripes, CacheEntryFactory factory)
Create a SelfPopulatingCache, with a specific number of stripes passed to the
underlying |
| Modifier and Type | Method and Description |
|---|---|
| public Element | get(final Object
an Object value key)Overrides net. Implements net. |
| protected static Element | Returns: the Element to be put back in the cacheBoth CacheEntryFactory can return an Element rather than just a regular value this method test this, making a fresh Element otherwise. |
| public void | |
| public void | refresh(boolean
whether the backing cache is quietly updated or not, if true replication will not occur quiet)Refresh the elements of this cache. |
| public Element | |
| public Element | |
| protected void | refreshElement(final Element
the Element to refresh element, Ehcache the underlying backingCache)Ehcache.Refresh a single element. |
| protected Element | Returns: the refreshed Elementthe Element to refresh element, Ehcache the underlying backingCache, boolean Ehcache.whether to use putQuiet or not, if true replication will not occur quiet)Refresh a single element. |
| factory | back to summary |
|---|---|
| protected final CacheEntryFactory factory A factory for creating entries, given a key | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| SelfPopulatingCache | back to summary |
|---|---|
| public SelfPopulatingCache(final Ehcache cache, final CacheEntryFactory factory) throws CacheException Creates a SelfPopulatingCache. | |
| SelfPopulatingCache | back to summary |
|---|---|
| public SelfPopulatingCache(Ehcache cache, int numberOfStripes, CacheEntryFactory factory) throws CacheException Create a SelfPopulatingCache, with a specific number of stripes passed to the
underlying | |
| get | back to summary |
|---|---|
| public Element get(final Object key) throws LockTimeoutException Overrides net. Implements net. Looks up an entry. creating it if not found.
| |
| makeAndCheckElement | back to summary |
|---|---|
| protected static Element makeAndCheckElement(Object key, Object value) throws CacheException Both CacheEntryFactory can return an Element rather than just a regular value this method test this, making a fresh Element otherwise. It also enforces the rule that the CacheEntryFactory must provide the same key (via equals() not necessarily same object) if it is returning an Element.
| |
| refresh | back to summary |
|---|---|
| public void refresh() throws CacheException Refresh the elements of this cache.
Refreshes bypass the Quiet methods are used, so that statistics are not affected. Note that the refreshed elements will not be replicated to any cache peers. Configure ehcache.xml to stop elements from being refreshed forever:
| |
| refresh | back to summary |
|---|---|
| public void refresh(boolean quiet) throws CacheException Refresh the elements of this cache.
Refreshes bypass the Quiet methods are used if argument 0 is true, so that statistics are not affected, but note that replication will then not occur Configure ehcache.xml to stop elements from being refreshed forever:
| |
| refresh | back to summary |
|---|---|
| public Element refresh(Object key) throws CacheException Refresh a single element.
Refreshes bypass the If the element is absent it is created Quiet methods are used, so that statistics are not affected. Note that the refreshed element will not be replicated to any cache peers.
| |
| refresh | back to summary |
|---|---|
| public Element refresh(Object key, boolean quiet) throws CacheException Refresh a single element.
Refreshes bypass the If the element is absent it is created Quiet methods are used if argument 1 is true, so that statistics are not affected, but note that replication will then not occur
| |
| refreshElement | back to summary |
|---|---|
| protected void refreshElement(final Element element, Ehcache backingCache) throws Exception Refresh a single element. | |
| refreshElement | back to summary |
|---|---|
| protected Element refreshElement(final Element element, Ehcache backingCache, boolean quiet) throws Exception Refresh a single element. | |