Interface CacheStrategy<T,​CacheType,​QueryType extends Query<T>>

    • Method Detail

      • isCacheable

        @Deprecated
        default boolean isCacheable​(QueryType ignoredQuery,
                                    boolean ignoredWillMergeRunners)
        Deprecated.
        This method is deprecated and retained for backward incompatibility. Returns whether the given query is cacheable or not. The willMergeRunners parameter can be used for distinguishing the caller is a broker or a data node.
        Parameters:
        ignoredQuery - the query to be cached
        ignoredWillMergeRunners - indicates that QueryRunnerFactory.mergeRunners(QueryProcessingPool, Iterable) will be called on the cached by-segment results
        Returns:
        true if the query is cacheable, otherwise false.
      • isCacheable

        default boolean isCacheable​(QueryType query,
                                    boolean willMergeRunners,
                                    boolean bySegment)
        Returns whether the given query is cacheable or not. The willMergeRunners parameter can be used for distinguishing the caller is a broker or a data node.
        Parameters:
        query - the query to be cached
        willMergeRunners - indicates that QueryRunnerFactory.mergeRunners(QueryProcessingPool, Iterable) will be called on the cached by-segment results
        bySegment - segment level or result level cache
        Returns:
        true if the query is cacheable, otherwise false.
      • computeCacheKey

        byte[] computeCacheKey​(QueryType query)
        Computes the per-segment cache key for the given query. Because this is a per-segment cache key, it should only include parts of the query that affect the results for a specific segment (i.e., the results returned from QueryRunnerFactory.createRunner(org.apache.druid.segment.Segment)).
        Parameters:
        query - the query to be cached
        Returns:
        the per-segment cache key
      • computeResultLevelCacheKey

        byte[] computeResultLevelCacheKey​(QueryType query)
        Computes the result-level cache key for the given query. The result-level cache will tack on datasource and interval details, so this key does not need to include datasource and interval. But it should include anything else that might affect the results of the query. Some implementations will need to include query parameters that are not used in computeCacheKey(QueryType) for the same query.
        Parameters:
        query - the query to be cached
        Returns:
        the result-level cache key
      • getCacheObjectClazz

        com.fasterxml.jackson.core.type.TypeReference<CacheType> getCacheObjectClazz()
        Returns the class type of what is used in the cache
        Returns:
        Returns the class type of what is used in the cache
      • prepareForCache

        com.google.common.base.Function<T,​CacheType> prepareForCache​(boolean isResultLevelCache)
        Returns a function that converts from the QueryType's result type to something cacheable.

        The resulting function must be thread-safe.

        Parameters:
        isResultLevelCache - indicates whether the function is invoked for result-level caching or segment-level caching
        Returns:
        a thread-safe function that converts the QueryType's result type into something cacheable
      • pullFromCache

        com.google.common.base.Function<CacheType,​T> pullFromCache​(boolean isResultLevelCache)
        A function that does the inverse of the operation that the function prepareForCache returns
        Parameters:
        isResultLevelCache - indicates whether the function is invoked for result-level caching or segment-level caching
        Returns:
        A function that does the inverse of the operation that the function prepareForCache returns
      • prepareForSegmentLevelCache

        default com.google.common.base.Function<T,​CacheType> prepareForSegmentLevelCache()
      • pullFromSegmentLevelCache

        default com.google.common.base.Function<CacheType,​T> pullFromSegmentLevelCache()
      • fetchAggregatorsFromCache

        static void fetchAggregatorsFromCache​(List<AggregatorFactory> aggregators,
                                              Iterator<Object> resultIter,
                                              boolean isResultLevelCache,
                                              CacheStrategy.AddToResultFunction addToResultFunction)
        Helper function used by TopN, GroupBy, Timeseries queries in pullFromCache(boolean). When using the result level cache, the agg values seen here are finalized values generated by AggregatorFactory.finalizeComputation(). These finalized values are deserialized from the cache as generic Objects, which will later be reserialized and returned to the user without further modification. Because the agg values are deserialized as generic Objects, the values are subject to the same type consistency issues handled by DimensionHandlerUtils.convertObjectToType() in the pullFromCache implementations for dimension values (e.g., a Float would become Double).