Class AbstractResourceCacheResolvable

    • Constructor Detail

      • AbstractResourceCacheResolvable

        public AbstractResourceCacheResolvable()
    • Method Detail

      • isCacheEnabled

        public boolean isCacheEnabled()
        Returns true if caching is enabled with this.
        Specified by:
        isCacheEnabled in interface ResourceCacheResolvable
        Returns:
        true if caching is enabled with this
      • setCacheEnabled

        public void setCacheEnabled​(boolean cacheEnabled)
        Sets flag whether or not this is enabled with caching.
        Parameters:
        cacheEnabled - flag whether or not this is enabled with caching
      • isCacheable

        public boolean isCacheable​(Resource resource)
        Returns true if the given 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.

        Specified by:
        isCacheable in interface ResourceCacheResolvable
        Parameters:
        resource - resource representation
        Returns:
        true if the given resource is cacheable
      • createCacheKey

        public ValueMap createCacheKey​(String resourceSpace,
                                       String operationKey,
                                       String resourcePath,
                                       Map<String,​Object> pathVariables,
                                       ExchangeHint exchangeHint)
        Description copied from interface: ResourceCacheResolvable
        Create cache key based on given operation key, resource path, path variables and exchange hint. Or return null if no cache should be available.
        Specified by:
        createCacheKey in interface ResourceCacheResolvable
        Parameters:
        resourceSpace - resource space name
        operationKey - a unique operation name given by a ResourceServiceBroker.
        resourcePath - absolute path of a Resource
        pathVariables - the variables to expand the template given by absPath
        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

        public Object toCacheData​(Resource resource)
                           throws IOException
        Convert the given 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.

        Specified by:
        toCacheData in interface ResourceCacheResolvable
        Parameters:
        resource - resource representation
        Returns:
        converted the given resource to a cacheable data object to be stored in ResourceDataCache
        Throws:
        IOException - if IO error occurs
      • fromCacheData

        public Resource fromCacheData​(Object cacheData)
                               throws IOException
        Convert and restore back the given 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.

        Specified by:
        fromCacheData in interface ResourceCacheResolvable
        Parameters:
        cacheData - cached data object that is stored in ResourceDataCache
        Returns:
        Resource object converted from the cacheData
        Throws:
        IOException - if IO error occurs