Interface ResourceCacheResolvable
-
- All Known Subinterfaces:
ResourceResolver
- All Known Implementing Classes:
AbstractResourceCacheResolvable
,AbstractResourceResolver
public interface ResourceCacheResolvable
An abstraction responsible for the following:- to return a
ResourceDataCache
as a cache store of resource representations, - to be able to check whether or not a specific
Resource
representation is cacheable, - to convert a
Resource
representation to a cacheable data object to be stored inResourceDataCache
, - and to convert a cached data object back to a
Resource
representation.
Note that a
Resource
object cannot necessarily be cached intoResourceDataCache
directly in every case. For example, if the underlyingResourceDataCache
depends on object serialization and if the givenResource
instance is not practically serializable to be restored back to the original state, then it could be meaningless to try to cache theResource
instance directly into the cache store. Therefore, an implementation may choose to implement methods in this interface to convert aResource
representation to a practically cacheable data object and convert the cached data object back to theResource
representation.For example, a JSON data based
ResourceCacheResolvable
implementation may have non-serializable JSON objects when resolving data from the backend. In that case, the implementation may choose to convert the JSON object to a string value to be cached. And, when restoring theResource
representation from a cached data (in this case, a string for the JSON object), the implementation may create a JSON object back to restore its original state. Of course, if theResource
implementation is practically cacheable, then those conversion methods may return theResource
object directly without having to implement any conversion logic. The same pattern can apply to other use cases. e.g, non-Serializable record object, etc.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ValueMap
createCacheKey(String resourceSpace, String operationKey, String absPath, Map<String,Object> pathVariables, ExchangeHint exchangeHint)
Create cache key based on given operation key, resource path, path variables and exchange hint.Resource
fromCacheData(Object cacheData)
ResourceDataCache
getResourceDataCache()
Returns aResourceDataCache
that represents the underlying cache store.boolean
isCacheable(Resource resource)
Returns true if the givenresource
is cacheable.boolean
isCacheEnabled()
Returns true if caching is enabled with this.Object
toCacheData(Resource resource)
Convert the givenresource
to a cacheable data object to be stored inResourceDataCache
.
-
-
-
Method Detail
-
isCacheEnabled
boolean isCacheEnabled()
Returns true if caching is enabled with this.- Returns:
- true if caching is enabled with this
-
isCacheable
boolean isCacheable(Resource resource)
Returns true if the givenresource
is cacheable.Note that if an implementation does not want to cache
Resource
representations at all for any reason, then it may always return false.ResourceServiceBroker
implementation should not try to cache anyResource
representations into cache store if this method returns false.- Parameters:
resource
- resource representation- Returns:
- true if the given
resource
is cacheable
-
createCacheKey
ValueMap createCacheKey(String resourceSpace, String operationKey, String absPath, Map<String,Object> pathVariables, ExchangeHint exchangeHint)
Create cache key based on given operation key, resource path, path variables and exchange hint. Or return null if no cache should be available.- Parameters:
resourceSpace
- resource space nameoperationKey
- a unique operation name given by aResourceServiceBroker
.absPath
- absolute path of aResource
pathVariables
- the variables to expand the template given byabsPath
exchangeHint
- a message exchange hint for the backend- Returns:
- cache key based on given operation key, resource path, path variables and exchange hint, or null if no cache should be available
-
toCacheData
Object toCacheData(Resource resource) throws IOException
Convert the givenresource
to a cacheable data object to be stored inResourceDataCache
.Implementations may simply return the
resource
object directly without any conversion if the theresource
object can be stored (for example, theresource
object is serializable) into the underlying cache store. Otherwise, theresource
object can be converted to something else and returned in order to be stored into the underlying cache store by implementations.- Parameters:
resource
- resource representation- Returns:
- converted the given
resource
to a cacheable data object to be stored inResourceDataCache
- Throws:
IOException
- if IO error occurs
-
fromCacheData
Resource fromCacheData(Object cacheData) throws IOException
Convert and restore back the givencacheData
from theResourceDataCache
to aResource
object.Implementations may simply cast the
cacheData
object directly toResource
object without any conversion if the the resource object was stored directly into the underlying cache store. Otherwise, thecacheData
object can be converted back to aResource
object by implementations.- Parameters:
cacheData
- cached data object that is stored inResourceDataCache
- Returns:
Resource
object converted from thecacheData
- Throws:
IOException
- if IO error occurs
-
getResourceDataCache
ResourceDataCache getResourceDataCache()
Returns aResourceDataCache
that represents the underlying cache store.Note that an implementation may return null if it doesn't want to have its own cache store representation. In that case, a
ResourceServiceBroker
implementation may use a defaultResourceDataCache
instance as a fallback cache store.- Returns:
- a
ResourceDataCache
that represents the underlying cache store
-
-