class PagersCacheContext implements CalculatedCacheContextInterface (View source)

Defines a cache context for "per page in a pager" caching.

Cache context ID: 'url.query_args.pagers' (to vary by all pagers). Calculated cache context ID: 'url.query_args.pagers:%pager_id', e.g. 'url.query_args.pagers:1' (to vary by the pager with ID 1).

Properties

protected PagerParametersInterface $pagerParams

The pager parameters.

Methods

__construct(PagerParametersInterface $pager_params)

Constructs a new PagersCacheContext object.

static string
getLabel()

Returns the label of the cache context.

string
getContext($pager_id = NULL)

Returns the string representation of the cache context.

getCacheableMetadata($pager_id = NULL)

Gets the cacheability metadata for the context based on the parameter value.

Details

__construct(PagerParametersInterface $pager_params)

Constructs a new PagersCacheContext object.

Parameters

PagerParametersInterface $pager_params

The pager parameters.

static string getLabel()

Returns the label of the cache context.

Return Value

string

The label of the cache context.

string getContext($pager_id = NULL)

Returns the string representation of the cache context.

A cache context service's name is used as a token (placeholder) cache key, and is then replaced with the string returned by this method.

Parameters

$pager_id

Return Value

string

The string representation of the cache context. When $parameter is NULL, a value representing all possible parameters must be generated.

Exceptions

LogicException

See also

PagerParametersInterface::findPage

CacheableMetadata getCacheableMetadata($pager_id = NULL)

Gets the cacheability metadata for the context based on the parameter value.

There are three valid cases for the returned CacheableMetadata object:

  • An empty object means this can be optimized away safely.
  • A max-age of 0 means that this context can never be optimized away. It will never bubble up and cache tags will not be used.
  • Any non-zero max-age and cache tags will bubble up into the cache item if this is optimized away to allow for invalidation if the context value changes.

Parameters

$pager_id

Return Value

CacheableMetadata

A cacheable metadata object.

Exceptions

LogicException