Search in sources :

Example 1 with DefaultResourceDataResult

use of com.okta.sdk.impl.ds.DefaultResourceDataResult in project okta-sdk-java by okta.

the class DefaultResourceCacheStrategy method readFromCache.

@Override
public ResourceDataResult readFromCache(ResourceDataRequest request) {
    if (!isCacheRetrievalEnabled(request)) {
        return null;
    }
    final CanonicalUri uri = request.getUri();
    final Class<? extends Resource> clazz = request.getResourceClass();
    Map<String, ?> data = null;
    // Prevent an expanded request to obtain a non-expanded resource from the cache
    String cacheKey = getCacheKey(request);
    if (!(request.getUri().hasQuery() && request.getUri().getQuery().containsKey("expand") ^ (cacheKey != null && cacheKey.contains("expand=")))) {
        data = getCachedValue(cacheKey, clazz);
    }
    // return if no data
    if (Collections.isEmpty(data)) {
        return null;
    }
    return new DefaultResourceDataResult(request.getAction(), uri, clazz, coerce(data));
}
Also used : CanonicalUri(com.okta.sdk.impl.http.CanonicalUri) DefaultResourceDataResult(com.okta.sdk.impl.ds.DefaultResourceDataResult)

Aggregations

DefaultResourceDataResult (com.okta.sdk.impl.ds.DefaultResourceDataResult)1 CanonicalUri (com.okta.sdk.impl.http.CanonicalUri)1