public interface ResourceCacheResolvable
ResourceDataCache
as a cache store of resource representations,Resource
representation is cacheable,Resource
representation to a cacheable data object to be stored in ResourceDataCache
,
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.
Modifier and Type | Method and 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 a
ResourceDataCache that represents the underlying cache store. |
boolean |
isCacheable(Resource resource)
Returns true if the given
resource is cacheable. |
boolean |
isCacheEnabled()
Returns true if caching is enabled with this.
|
Object |
toCacheData(Resource resource)
Convert the given
resource to a cacheable data object to be stored in ResourceDataCache . |
boolean isCacheEnabled()
boolean isCacheable(Resource resource)
resource
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
any Resource
representations into cache store if this method returns false.
resource
- resource representationresource
is cacheableValueMap createCacheKey(String resourceSpace, String operationKey, String absPath, Map<String,Object> pathVariables, ExchangeHint exchangeHint)
resourceSpace
- resource space nameoperationKey
- a unique operation name given by a ResourceServiceBroker
.absPath
- absolute path of a Resource
pathVariables
- the variables to expand the template given by absPath
exchangeHint
- a message exchange hint for the backendObject toCacheData(Resource resource) throws IOException
resource
to a cacheable data object to be stored in ResourceDataCache
.
Implementations may simply return the resource
object directly without any conversion if the the
resource
object can be stored (for example, the resource
object is serializable) into the
underlying cache store.
Otherwise, the resource
object can be converted to something else and returned in order to be stored
into the underlying cache store by implementations.
resource
- resource representationresource
to a cacheable data object to be stored in ResourceDataCache
IOException
- if IO error occursResource fromCacheData(Object cacheData) throws IOException
cacheData
from the ResourceDataCache
to a Resource
object.
Implementations may simply cast the cacheData
object directly to Resource
object without
any conversion if the the resource object was stored directly into the underlying cache store.
Otherwise, the cacheData
object can be converted back to a Resource
object by implementations.
cacheData
- cached data object that is stored in ResourceDataCache
Resource
object converted from the cacheData
IOException
- if IO error occursResourceDataCache getResourceDataCache()
ResourceDataCache
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 default ResourceDataCache
instance as a fallback cache store.
ResourceDataCache
that represents the underlying cache storeCopyright © 2017–2020 Hippo B.V. (http://www.onehippo.com). All rights reserved.