class NodeAccessGrantsCacheContext extends UserCacheContextBase implements CalculatedCacheContextInterface (View source)

Defines the node access view cache context service.

Cache context ID: 'user.node_grants' (to vary by all operations' grants). Calculated cache context ID: 'user.node_grants:%operation', e.g. 'user.node_grants:view' (to vary by the view operation's grants).

This allows for node access grants-sensitive caching when listing nodes.

Properties

protected AccountInterface $user

The account object.

from  UserCacheContextBase

Methods

__construct(AccountInterface $user)

Constructs a new UserCacheContextBase class.

static string
getLabel()

Returns the label of the cache context.

string
getContext($operation = NULL)

Returns the string representation of the cache context.

string
checkNodeGrants(string $operation)

Checks the node grants for the given operation.

getCacheableMetadata($operation = NULL)

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

Details

__construct(AccountInterface $user)

Constructs a new UserCacheContextBase class.

Parameters

AccountInterface $user

The current user.

static string getLabel()

Returns the label of the cache context.

Return Value

string

The label of the cache context.

string getContext($operation = 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

$operation

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

protected string checkNodeGrants(string $operation)

Checks the node grants for the given operation.

Parameters

string $operation

The operation to check the node grants for.

Return Value

string

The string representation of the cache context.

CacheableMetadata getCacheableMetadata($operation = 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

$operation

Return Value

CacheableMetadata

A cacheable metadata object.

Exceptions

LogicException