Interface ResourceCacheResolvable
- All Known Subinterfaces:
ResourceResolver
- All Known Implementing Classes:
AbstractResourceCacheResolvable
,AbstractResourceResolver
- 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 into ResourceDataCache
directly in
every case. For example, if the underlying ResourceDataCache
depends on object serialization and if
the given Resource
instance is not practically serializable to be restored back to the original state,
then it could be meaningless to try to cache the Resource
instance directly into the cache store.
Therefore, an implementation may choose to implement methods in this interface to convert a Resource
representation to a practically cacheable data object and convert the cached data object back to the Resource
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 the Resource
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 the Resource
implementation is practically cacheable, then those conversion
methods may return the Resource
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
Modifier and TypeMethodDescriptioncreateCacheKey
(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.fromCacheData
(Object cacheData) Returns aResourceDataCache
that represents the underlying cache store.boolean
isCacheable
(Resource resource) Returns true if the givenresource
is cacheable.boolean
Returns true if caching is enabled with this.toCacheData
(Resource resource) Convert the givenresource
to a cacheable data object to be stored inResourceDataCache
.
-
Method Details
-
isCacheEnabled
boolean isCacheEnabled()Returns true if caching is enabled with this.- Returns:
- true if caching is enabled with this
-
isCacheable
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
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
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
-