Class ReadThroughEntityCache<CACHEKEY extends Serializable,ENTITYID extends Serializable,ENTITY>
- java.lang.Object
-
- com.atlassian.confluence.impl.cache.ReadThroughEntityCache<CACHEKEY,ENTITYID,ENTITY>
-
- Type Parameters:
CACHEKEY
- the cache key type. Must beSerializable
.ENTITYID
- the entity ID type, used as the value in the cache. Must beSerializable
.ENTITY
- the entity type, as will be returned from theget(Serializable, Supplier, Predicate)
method
- All Implemented Interfaces:
ReadThroughCache<CACHEKEY,ENTITY>
public final class ReadThroughEntityCache<CACHEKEY extends Serializable,ENTITYID extends Serializable,ENTITY> extends Object implements ReadThroughCache<CACHEKEY,ENTITY>
An implementation ofReadThroughCache
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.
- Since:
- 7.5
-
-
Constructor Summary
Constructors Constructor Description ReadThroughEntityCache(ReadThroughCache<CACHEKEY,ENTITYID> backingCache, Function<ENTITYID,ENTITY> entityLoader, Function<ENTITY,ENTITYID> idExtractor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <E extends ConfluenceEntityObject,K extends Serializable>
ReadThroughCache<K,E>forConfluenceEntityObjects(ReadThroughCache<K,Long> cache, Function<Long,E> entityLoader)
Creates a newReadThroughCache
for use withConfluenceEntityObject
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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.atlassian.confluence.impl.cache.ReadThroughCache
get
-
-
-
-
Constructor Detail
-
ReadThroughEntityCache
public ReadThroughEntityCache(ReadThroughCache<CACHEKEY,ENTITYID> backingCache, Function<ENTITYID,ENTITY> entityLoader, Function<ENTITY,ENTITYID> idExtractor)
- Parameters:
backingCache
- The underlyingReadThroughCache
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.
-
-
Method Detail
-
forConfluenceEntityObjects
public static <E extends ConfluenceEntityObject,K extends Serializable> ReadThroughCache<K,E> forConfluenceEntityObjects(ReadThroughCache<K,Long> cache, Function<Long,E> entityLoader)
Creates a newReadThroughCache
for use withConfluenceEntityObject
entity types. Uses the Long ID of the entity as the cached value.- Type Parameters:
E
- The entity type (must be a subtype ofConfluenceEntityObject
).K
- The type of the cache key (must beSerializable
).- Parameters:
cache
- The underlyingReadThroughCache
to use.entityLoader
- The function for resolving an entity ID into an entity (e.g. a DAO method reference).
-
get
public ENTITY get(CACHEKEY cacheKey, Supplier<ENTITY> delegateLoader, Predicate<ENTITY> entityTester)
Retrieve the value for the given key. If the value is in the cache this will be returned, else the given delegate will be called to retrieve the value. If the delegate returns a value, and if it passes the given filter, it will be placed in the cache and returned. If the filter rejects the value, nothing will be placed in the cache but the value will be returned from the method.- Specified by:
get
in interfaceReadThroughCache<CACHEKEY extends Serializable,ENTITYID extends Serializable>
- Parameters:
cacheKey
- the key to resolve in the cachedelegateLoader
- ASupplier
which will be called if there is no value in the cache (may return null).entityTester
- APredicate
that will be used to test the validity of any value in the cache or loaded from the supplier- Returns:
- the cached value, or the value which was loaded from the supplier (may be null)
-
getBulk
public Map<CACHEKEY,ENTITY> getBulk(Set<CACHEKEY> keys, Function<Set<CACHEKEY>,Map<CACHEKEY,ENTITY>> entityBulkLoader)
Retrieves multiple values for the given keys. Any entries not already present in the cache will be supplied via the delegate loader.- Specified by:
getBulk
in interfaceReadThroughCache<CACHEKEY extends Serializable,ENTITYID extends Serializable>
-
remove
public void remove(CACHEKEY cacheKey)
Description copied from interface:ReadThroughCache
Removs the cache entry for the given key.- Specified by:
remove
in interfaceReadThroughCache<CACHEKEY extends Serializable,ENTITYID extends Serializable>
-
removeAll
public void removeAll()
Description copied from interface:ReadThroughCache
Removes all cache entries.- Specified by:
removeAll
in interfaceReadThroughCache<CACHEKEY extends Serializable,ENTITYID extends Serializable>
-
-