CACHEKEY
- the cache key type. Must be Serializable
.ENTITYID
- the entity ID type, used as the value in the cache. Must be Serializable
.ENTITY
- the entity type, as will be returned from the get(Serializable, Supplier, Predicate)
methodpublic final class ReadThroughEntityCache<CACHEKEY extends Serializable,ENTITYID extends Serializable,ENTITY> extends Object implements ReadThroughCache<CACHEKEY,ENTITY>
ReadThroughCache
which caches the IDs of entity objects against arbitrary keys. When
fetched from the cache, the IDs will be deferenced back to the required entity objects before being returned.
Contains logic to handle cases where the cache contains a stale entity ID, i.e. where an entity for that ID no longer exists.
Constructor and Description |
---|
ReadThroughEntityCache(ReadThroughCache<CACHEKEY,ENTITYID> backingCache,
Function<ENTITYID,ENTITY> entityLoader,
Function<ENTITY,ENTITYID> idExtractor) |
Modifier and Type | Method and Description |
---|---|
static <E extends ConfluenceEntityObject,K extends Serializable> |
forConfluenceEntityObjects(ReadThroughCache<K,Long> cache,
Function<Long,E> entityLoader)
Creates a new
ReadThroughCache for use with ConfluenceEntityObject entity types. |
ENTITY |
get(CACHEKEY cacheKey,
Supplier<ENTITY> delegateLoader,
Predicate<ENTITY> entityTester)
Retrieve the value for the given key.
|
Map<CACHEKEY,ENTITY> |
getBulk(Set<CACHEKEY> keys,
Function<Set<CACHEKEY>,Map<CACHEKEY,ENTITY>> entityBulkLoader)
Retrieves multiple values for the given keys.
|
void |
remove(CACHEKEY cacheKey)
Removs the cache entry for the given key.
|
void |
removeAll()
Removes all cache entries.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
get
public ReadThroughEntityCache(ReadThroughCache<CACHEKEY,ENTITYID> backingCache, Function<ENTITYID,ENTITY> entityLoader, Function<ENTITY,ENTITYID> idExtractor)
backingCache
- The underlying ReadThroughCache
to use.entityLoader
- The function for resolving an entity ID into an entity (e.g. a DAO method reference).idExtractor
- The function for extracting the ID from an entity.public static <E extends ConfluenceEntityObject,K extends Serializable> ReadThroughCache<K,E> forConfluenceEntityObjects(ReadThroughCache<K,Long> cache, Function<Long,E> entityLoader)
ReadThroughCache
for use with ConfluenceEntityObject
entity types. Uses the Long
ID of the entity as the cached value.E
- The entity type (must be a subtype of ConfluenceEntityObject
).K
- The type of the cache key (must be Serializable
).cache
- The underlying ReadThroughCache
to use.entityLoader
- The function for resolving an entity ID into an entity (e.g. a DAO method reference).public ENTITY get(CACHEKEY cacheKey, Supplier<ENTITY> delegateLoader, Predicate<ENTITY> entityTester)
get
in interface ReadThroughCache<CACHEKEY extends Serializable,ENTITY>
cacheKey
- the key to resolve in the cachedelegateLoader
- A Supplier
which will be called if there is no value in the cache (may return null).entityTester
- A Predicate
that will be used to test the validity of any value in the cache or loaded from the supplierpublic Map<CACHEKEY,ENTITY> getBulk(Set<CACHEKEY> keys, Function<Set<CACHEKEY>,Map<CACHEKEY,ENTITY>> entityBulkLoader)
getBulk
in interface ReadThroughCache<CACHEKEY extends Serializable,ENTITY>
public void remove(CACHEKEY cacheKey)
ReadThroughCache
remove
in interface ReadThroughCache<CACHEKEY extends Serializable,ENTITY>
public void removeAll()
ReadThroughCache
removeAll
in interface ReadThroughCache<CACHEKEY extends Serializable,ENTITY>
Copyright © 2003–2023 Atlassian. All rights reserved.
View cookie preferences