Class FederationAccessManagerWithHierarchicalCache
- All Implemented Interfaces:
StatsProvider,FederationAccessManager
The cache consists of two cache layers arranged hierarchically. Requests are first looked up in the primary cache layer. If no cached entry is found, the secondary cache layer is consulted. Entries retrieved from the secondary layer are promoted to the primary layer to improve the performance of future lookups.
Both data retrieval requests and cardinality requests are cached. Cache keys
are represented by PersistentCacheKey objects, which uniquely
identify a request, the targeted federation member, and the type of cached
response.
To reduce duplicate request execution, this class stores
CompletableFuture instances in the cache whenever possible. If the
underlying cache layers preserve the cached futures, concurrent requests for
the same data may share both the same future and the same underlying request
execution. However, some cache implementations may store serialized or
reconstructed representations of cached values rather than the original
future instance. In such cases, the degree to which concurrent requests can
be coalesced depends on the behavior of the underlying cache layers.
Cache replacement and invalidation behavior are determined by the policies configured for the underlying cache layers.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class se.liu.ida.hefquin.federation.access.impl.FederationAccessManagerWithCache
FederationAccessManagerWithCache.Key, FederationAccessManagerWithCache.MyDefaultCachePolicies -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final HierarchicalCache<PersistentCacheKey, CompletableFuture<? extends DataRetrievalResponse<?>>, PersistentCacheEntry> Fields inherited from class se.liu.ida.hefquin.federation.access.impl.FederationAccessManagerWithCache
cacheHitsBRTPF, cacheHitsBRTPFCardinality, cacheHitsOther, cacheHitsSPARQL, cacheHitsSPARQLCardinality, cacheHitsTPF, cacheHitsTPFCardinality, cacheMap, cacheRequestsBRTPF, cacheRequestsOther, cacheRequestsSPARQL, cacheRequestsTPF, fedAccMan -
Constructor Summary
ConstructorsConstructorDescriptionFederationAccessManagerWithHierarchicalCache(FederationAccessManager fedAccMan, Cache<PersistentCacheKey, CompletableFuture<? extends DataRetrievalResponse<?>>> l1Cache, Cache<PersistentCacheKey, CompletableFuture<? extends DataRetrievalResponse<?>>> l2Cache) Creates a federation access manager with a ChronicleMap-backed persistent cache using the given capacity and cache policies. -
Method Summary
Modifier and TypeMethodDescription<ReqType extends DataRetrievalRequest,RespType extends DataRetrievalResponse<?>, MemberType extends FederationMember>
CompletableFuture<CardinalityResponse> issueCardinalityRequest(ReqType req, MemberType fm) Issues a cardinality request for the given request and federation member.<ReqType extends DataRetrievalRequest,RespType extends DataRetrievalResponse<?>, MemberType extends FederationMember>
CompletableFuture<RespType> issueRequest(ReqType req, MemberType fm) Issues a request for the given request and federation member.voidshutdown()Shuts down all thread pools associated with this federation access manager.Methods inherited from class se.liu.ida.hefquin.federation.access.impl.FederationAccessManagerWithCache
getStats, resetStats
-
Field Details
-
cache
protected final HierarchicalCache<PersistentCacheKey,CompletableFuture<? extends DataRetrievalResponse<?>>, cachePersistentCacheEntry>
-
-
Constructor Details
-
FederationAccessManagerWithHierarchicalCache
public FederationAccessManagerWithHierarchicalCache(FederationAccessManager fedAccMan, Cache<PersistentCacheKey, CompletableFuture<? extends DataRetrievalResponse<?>>> l1Cache, Cache<PersistentCacheKey, throws IOExceptionCompletableFuture<? extends DataRetrievalResponse<?>>> l2Cache) Creates a federation access manager with a ChronicleMap-backed persistent cache using the given capacity and cache policies.- Parameters:
fedAccMan- the wrapped federation access managerl1Cache-l2Cache-- Throws:
IOException
-
-
Method Details
-
issueRequest
public <ReqType extends DataRetrievalRequest,RespType extends DataRetrievalResponse<?>, CompletableFuture<RespType> issueRequestMemberType extends FederationMember> (ReqType req, MemberType fm) throws FederationAccessException Issues a request for the given request and federation member.Checks the cache first and returns a cached response if available. Otherwise, delegates the request to the wrapped federation access manager and caches the result asynchronously.
- Specified by:
issueRequestin interfaceFederationAccessManager- Overrides:
issueRequestin classFederationAccessManagerWithCache- Parameters:
req- the data retrieval request (TPF, BRTPF, or SPARQL)fm- the federation member handling the request- Returns:
- a
CompletableFuturewith the response - Throws:
FederationAccessException- if the request failsIllegalStateException- if the request/member combination is unsupported
-
issueCardinalityRequest
public <ReqType extends DataRetrievalRequest,RespType extends DataRetrievalResponse<?>, CompletableFuture<CardinalityResponse> issueCardinalityRequestMemberType extends FederationMember> (ReqType req, MemberType fm) throws FederationAccessException Issues a cardinality request for the given request and federation member.Checks the cache first and returns a cached response if available. Otherwise, delegates the request to the wrapped federation access manager and caches the result asynchronously.
- Specified by:
issueCardinalityRequestin interfaceFederationAccessManager- Overrides:
issueCardinalityRequestin classFederationAccessManagerWithCache- Parameters:
req- the data retrieval request (TPF, BRTPF, or SPARQL)fm- the federation member handling the request- Returns:
- a
CompletableFuturewith the cardinality response - Throws:
FederationAccessException- if the request failsIllegalStateException- if the request/member combination is unsupported
-
shutdown
public void shutdown()Description copied from class:FederationAccessManagerWithCacheShuts down all thread pools associated with this federation access manager.- Specified by:
shutdownin interfaceFederationAccessManager- Overrides:
shutdownin classFederationAccessManagerWithCache
-