Package org.ow2.authzforce.core.pdp.api
Interface DecisionCache
-
- All Superinterfaces:
AutoCloseable
,Closeable
public interface DecisionCache extends Closeable
Authorization (XACML) decision result cache. ImplementsCloseable
because a cache may use resources external to the JVM such as a disk or connection to a remote server for persistence, replication, clustering, etc. Therefore, these resources must be released by callingCloseable.close()
when it is no longer needed.Implementations of this interface are expected to be thread-safe, and allow access by multiple concurrent threads.
Note: This is quite similar to Guava Cache interface but specialized for specific type of key and value.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
DecisionCache.Factory<CONF_T extends org.ow2.authzforce.xmlns.pdp.ext.AbstractDecisionCache>
Factory for creating instance of DecisionCache extension
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description DecisionResult
get(DecisionRequest request, EvaluationContext evalCtx)
Get the decision result from the cache for the given decision request.<DECISION_REQ_T extends DecisionRequest>
Map<DECISION_REQ_T,DecisionResult>getAll(List<DECISION_REQ_T> requests)
Gets the decision result(s) from the cache for the given decision request(s).boolean
isEvaluationContextRequired()
Tells the PDP to always pass a valid/non-nullEvaluationContext
argument - representing the PDP's evaluation context - to other methods of this API withEvaluationContext
arg.void
put(DecisionRequest request, DecisionResult result, EvaluationContext evalCtx)
Puts a decision request and corresponding result in cache.<DECISION_REQ_T extends DecisionRequest>
voidputAll(Map<DECISION_REQ_T,DecisionResult> resultsByRequest)
Puts decision requests and corresponding results in cache.
-
-
-
Method Detail
-
isEvaluationContextRequired
boolean isEvaluationContextRequired()
Tells the PDP to always pass a valid/non-nullEvaluationContext
argument - representing the PDP's evaluation context - to other methods of this API withEvaluationContext
arg. Else the PDP may pass a null value to save time and memory.- Returns:
- true iff a non-null
EvaluationContext
argument - referring to the PDP's evaluation context - is required for all methods of this API withEvaluationContext
arg of thisDecisionCache
.
-
get
DecisionResult get(DecisionRequest request, EvaluationContext evalCtx)
Get the decision result from the cache for the given decision request.- Parameters:
request
- individual decision requestevalCtx
- evaluation context that can be used to save context about any partial/preliminary evaluation done by this decision cache when there is no cached result for {code request} yet. In this case, the PDP will call backput(DecisionRequest, DecisionResult, EvaluationContext)
with this sameevalCtx
after the PDP has computed the new result. Therefore, this allows the decision cache to reuse some context during an evaluation, and also to do some evaluation itself. This argument may be null if not required, i.e.isEvaluationContextRequired()
returns false.- Returns:
- the corresponding decision result from cache; null if there is no such result in cache.
-
getAll
<DECISION_REQ_T extends DecisionRequest> Map<DECISION_REQ_T,DecisionResult> getAll(List<DECISION_REQ_T> requests)
Gets the decision result(s) from the cache for the given decision request(s). The ability to get multiple cached results at once allows the Cache implementation to optimize the retrieval by requesting all in the same request, e.g. if the cache is in a remote storage/server.- Parameters:
requests
- individual decision request(s)- Returns:
- a map where each entry key is a request from
requests
, and the value is the corresponding decision result from cache. If there is no such result in cache, the key must not be present in the map. In other words, each request inrequests
must be a key in the Map returned, except if there is no corresponding result in cache. Therefore, there must not be any null key/value in the map.
-
put
void put(DecisionRequest request, DecisionResult result, EvaluationContext evalCtx)
Puts a decision request and corresponding result in cache.- Parameters:
request
- individual decision requestresult
- the corresponding decision resultevalCtx
- evaluation context that can be used to retrieve context about any partial/preliminary evaluation done by this decision cache whenget(DecisionRequest, EvaluationContext)
was called in the same request context. This argument may be null if not required, i.e.isEvaluationContextRequired()
returns false.
-
putAll
<DECISION_REQ_T extends DecisionRequest> void putAll(Map<DECISION_REQ_T,DecisionResult> resultsByRequest)
Puts decision requests and corresponding results in cache. The ability to put multiple cache entries at once allows the Cache implementation to optimize the creation/update by doing them all in the same request, e.g. if the cache is in a remote storage/server.- Parameters:
resultsByRequest
- (request, result) pairs as key-value pairs to be cached
-
-