Drupal 8  8.0.2
Cache Class Reference

Static Public Member Functions

static mergeContexts (array $a=[], array $b=[])
 
static mergeTags (array $a=[], array $b=[])
 
static mergeMaxAges ($a=Cache::PERMANENT, $b=Cache::PERMANENT)
 
static validateTags (array $tags)
 
static buildTags ($prefix, array $suffixes, $glue= ':')
 
static invalidateTags (array $tags)
 
static getBins ()
 
static keyFromQuery (SelectInterface $query)
 

Data Fields

const PERMANENT = CacheBackendInterface::CACHE_PERMANENT
 

Detailed Description

Helper methods for cache.

Member Function Documentation

static buildTags (   $prefix,
array  $suffixes,
  $glue = ':' 
)
static

Build an array of cache tags from a given prefix and an array of suffixes.

Each suffix will be converted to a cache tag by appending it to the prefix, with a colon between them.

Parameters
string$prefixA prefix string.
array$suffixesAn array of suffixes. Will be cast to strings.
string$glueA string to be used as glue for concatenation. Defaults to a colon.
Returns
string[] An array of cache tags.

Referenced by PermissionsHashGenerator\generate(), MenuTreeStorage\rebuild(), MenuTreeStorage\save(), and CacheTest\testBuildTags().

Here is the caller graph for this function:

static getBins ( )
static

Gets all cache bin services.

Returns
array An array of cache backend objects keyed by cache bins.

References Drupal\getContainer().

Referenced by WebTestBase\refreshVariables(), BrowserTestBase\refreshVariables(), ConfigTranslationDeleteForm\submitForm(), and ClearTest\testFlushAllCaches().

Here is the call graph for this function:

Here is the caller graph for this function:

static invalidateTags ( array  $tags)
static

Marks cache items from all bins with any of the specified tags as invalid.

Parameters
string[]$tags The list of tags to invalidate cache items for.

References Drupal\service().

Referenced by CachePluginBase\cacheFlush(), CacheCollector\clear(), ViewsData\clear(), EntityTypeBundleInfo\clearCachedBundles(), DefaultPluginManager\clearCachedDefinitions(), EntityFieldManager\clearCachedFieldDefinitions(), LanguageConfigOverride\delete(), AliasStorage\delete(), Config\delete(), BookManager\deleteFromBook(), ImageStyle\flush(), ConfigEntityBase\invalidateTagsOnDelete(), ConfigEntityBase\invalidateTagsOnSave(), CacheRouterRebuildSubscriber\onRouterFinished(), MenuRouterRebuildSubscriber\onRouterRebuild(), Shortcut\postSave(), Comment\postSave(), Item\postSave(), Block\postSave(), ConfigFactory\rename(), Registry\reset(), EntityViewBuilder\resetCache(), ContentEntityStorageBase\resetCache(), ThemeInstaller\resetSystem(), LanguageConfigOverride\save(), AliasStorage\save(), Config\save(), BookManager\saveBookLink(), BlockViewBuilderTest\testBlockViewBuilderViewAlter(), BookTest\testBookNavigationCacheContext(), BlockCacheTest\testCachePerRole(), ContactLinkTest\testContactLink(), EntityWithUriCacheTagsTestBase\testEntityUri(), PageCacheTest\testFormImmutability(), GenericCacheBackendUnitTestBase\testInvalidateTags(), NodeEntityViewModeAlterTest\testNodeViewModeChange(), PageCacheTest\testPageCacheTags(), PageCacheTest\testPageCacheTagsIndependentFromCacheabilityHeaders(), PathAliasTest\testPathCache(), EntityCacheTagsTestBase\testReferencedEntity(), and TrackerTest\testTrackerUser().

Here is the call graph for this function:

Here is the caller graph for this function:

static keyFromQuery ( SelectInterface  $query)
static

Generates a hash from a query object, to be used as part of the cache key.

This smart caching strategy saves Drupal from querying and rendering to HTML when the underlying query is unchanged.

Expensive queries should use the query builder to create the query and then call this function. Executing the query and formatting results should happen in a #pre_render callback.

Parameters
\Drupal\Core\Database\Query\SelectInterface$queryA select query object.
Returns
string A hash of the query arguments.

References SelectInterface\getArguments(), and SelectInterface\preExecute().

Here is the call graph for this function:

static mergeMaxAges (   $a = Cache::PERMANENT,
  $b = Cache::PERMANENT 
)
static

Merges max-age values (expressed in seconds), finds the lowest max-age.

Ensures infinite max-age (Cache::PERMANENT) is taken into account.

Parameters
int$aMax age value to merge.
int$bMax age value to merge.
Returns
int The minimum max-age value.

References Cache\PERMANENT.

Referenced by CachePluginBase\getCacheMaxAge(), AccessResult\inheritCacheability(), CacheableMetadata\merge(), BlockAccessControlHandler\mergeCacheabilityFromConditions(), and CacheTest\testMergeMaxAges().

Here is the caller graph for this function:

static mergeTags ( array  $a = [],
array  $b = [] 
)
static

Merges arrays of cache tags and removes duplicates.

The cache tags array is returned in a format that is valid for ::set().

When caching elements, it is necessary to collect all cache tags into a single array, from both the element itself and all child elements. This allows items to be invalidated based on all tags attached to the content they're constituted from.

Parameters
array$aCache tags array to merge.
array$bCache tags array to merge.
Returns
string[] The merged array of cache tags.

Referenced by BlockViewBuilderTest\assertBlockRenderedWithExpectedCacheability(), RenderCacheIntegrationTest\assertCacheTagsForEntityBasedView(), RendererTestBase\assertRenderCacheItem(), ForumController\build(), FrontPageTest\doTestFrontPageViewCacheTags(), EntityViewBuilder\getBuildDefaults(), ForumBlockBase\getCacheTags(), SystemBrandingBlock\getCacheTags(), AggregatorFeedBlock\getCacheTags(), CachePluginBase\getCacheTags(), ConfigBase\getCacheTags(), CachePluginBase\getRowCacheTags(), EntityTestController\listEntitiesAlphabetically(), CacheableMetadata\merge(), EntityViewBuilder\resetCache(), RenderCache\set(), BlockContentCacheTagsTest\testBlock(), BlockViewBuilderTest\testBlockViewBuilderBuildAlter(), CommentRssTest\testCommentRss(), EditorFileReferenceFilterTest\testEditorFileReferenceFilter(), EntityWithUriCacheTagsTestBase\testEntityUri(), CacheTest\testMergeTags(), EntityCacheTagsTestBase\testReferencedEntity(), RendererTest\testRenderCache(), SearchPageCacheTagsTest\testSearchTagsBubbling(), TrackerTest\testTrackerAll(), TrackerTest\testTrackerUser(), ImageFormatter\viewElements(), and ResponsiveImageFormatter\viewElements().

Here is the caller graph for this function:

static validateTags ( array  $tags)
static

Validates an array of cache tags.

Can be called before using cache tags in operations, to ensure validity.

Parameters
string[]$tags An array of cache tags.
Deprecated:
Use assert('::assertAllStrings($tags)');
Exceptions
\LogicException

Referenced by CacheTest\testValidateTags().

Here is the caller graph for this function:

Field Documentation

Indicates that the item should never be removed unless explicitly deleted.

Referenced by BookManager\bookSubtreeData(), Registry\build(), ElementInfoManager\buildInfo(), CachePluginBase\cacheSet(), ViewsData\cacheSet(), CachePluginBase\cacheSetMaxAge(), Time\cacheSetMaxAge(), CacheableMetadata\createFromRenderArray(), BookManager\doBookTreeBuild(), Renderer\doRender(), DatabaseBackend\garbageCollection(), PermissionsHashGenerator\generate(), Internal\generateFormatTagsSetting(), EntityTypeBundleInfo\getAllBundleInfo(), EntityFieldManager\getBaseFieldDefinitions(), BreakpointManager\getBreakpointsByGroup(), CurrentUser\getCacheMaxAge(), SystemMessagesBlock\getCacheMaxAge(), AttachedRenderingBlock\getCacheMaxAge(), Fixed\getCacheMaxAge(), RendererBase\getCacheMaxAge(), Node\getCacheMaxAge(), TestAccessBlock\getCacheMaxAge(), QueryParameter\getCacheMaxAge(), User\getCacheMaxAge(), Raw\getCacheMaxAge(), Permission\getCacheMaxAge(), Role\getCacheMaxAge(), Serializer\getCacheMaxAge(), LocalTaskDefault\getCacheMaxAge(), MenuLinkBase\getCacheMaxAge(), Tid\getCacheMaxAge(), SortPluginBase\getCacheMaxAge(), QueryPluginBase\getCacheMaxAge(), ExposedFormPluginBase\getCacheMaxAge(), SqlBase\getCacheMaxAge(), FilterPluginBase\getCacheMaxAge(), EntityFieldManager\getExtraFields(), EntityFieldManager\getFieldDefinitions(), EntityFieldManager\getFieldMap(), EntityFieldManager\getFieldStorageDefinitions(), BreakpointManager\getGroups(), LocalTaskManager\getLocalTasksForRoute(), MenuTreeStorage\loadTreeData(), RenderCache\maxAgeToExpire(), CacheableMetadata\merge(), Cache\mergeMaxAges(), CacheTest\mergeMaxAgesProvider(), RoutePreloader\onRequest(), RouteProvider\preLoadRoutes(), MemoryBackend\prepareItem(), DatabaseBackend\prepareItem(), PhpBackend\prepareItem(), ApcuBackend\prepareItem(), RendererPlaceholdersTest\providerPlaceholders(), BubbleableMetadataTest\providerTestApplyTo(), MenuLinkTreeTest\providerTestBuildCacheability(), CacheableMetadataTest\providerTestCreateFromObject(), CacheableMetadataTest\providerTestCreateFromRenderArray(), BubbleableMetadataTest\providerTestCreateFromRenderArray(), CacheableMetadataTest\providerTestMerge(), BubbleableMetadataTest\providerTestMerge(), DatabaseBackend\schemaDefinition(), Registry\setCache(), DefaultPluginManager\setCachedDefinitions(), PlaceholderGenerator\shouldAutomaticallyPlaceholder(), DynamicPageCacheSubscriber\shouldCacheResponse(), UrlGeneratorTest\testAbsoluteURLGeneration(), UrlGeneratorTest\testAliasGeneration(), UrlGeneratorTest\testAliasGenerationWithOptions(), UrlGeneratorTest\testAliasGenerationWithParameters(), UrlGeneratorTest\testBaseURLGeneration(), BlockViewBuilderTest\testBlockViewBuilderBuildAlter(), ForumBreadcrumbBuilderBaseTest\testBuild(), ForumListingBreadcrumbBuilderTest\testBuild(), ForumNodeBreadcrumbBuilderTest\testBuild(), PathBasedBreadcrumbBuilderTest\testBuildOnFrontpage(), PathBasedBreadcrumbBuilderTest\testBuildWithException(), BreadcrumbManagerTest\testBuildWithMultipleApplyingBuilders(), PathBasedBreadcrumbBuilderTest\testBuildWithNonProcessedPath(), BreadcrumbManagerTest\testBuildWithOneNotApplyingBuilders(), PathBasedBreadcrumbBuilderTest\testBuildWithOnePathElement(), BreadcrumbManagerTest\testBuildWithoutBuilder(), BreadcrumbManagerTest\testBuildWithSingleBuilder(), PathBasedBreadcrumbBuilderTest\testBuildWithThreePathElements(), PathBasedBreadcrumbBuilderTest\testBuildWithTwoPathElements(), PathBasedBreadcrumbBuilderTest\testBuildWithUserPath(), RendererPlaceholdersTest\testCacheableParent(), AccessResultTest\testCacheContexts(), AccessResultTest\testCacheMaxAge(), EntityUnitTest\testCacheMaxAge(), AccessResultTest\testCacheTags(), RendererBubblingTest\testConditionalCacheContextBubblingSelfHealing(), ContentTranslationManageAccessCheckTest\testCreateAccess(), GenericCacheBackendUnitTestBase\testDeleteAll(), BackendChainImplementationUnitTest\testDeleteAllPropagation(), BackendChainImplementationUnitTest\testDeleteTagsPropagation(), LibraryDiscoveryCollectorTest\testDestruct(), LanguageNegotiationUrlTest\testDomain(), EntityDisplayTest\testEntityDisplayInvalidateCacheTags(), EntityTypeBundleInfoTest\testGetAllBundleInfo(), EntityFieldManagerTest\testGetBaseFieldDefinitionsWithCaching(), EntityFieldManagerTest\testGetExtraFields(), EntityFieldManagerTest\testGetFieldDefinitionsWithCaching(), EntityFieldManagerTest\testGetFieldStorageDefinitionsWithCaching(), LocalTaskManagerTest\testGetLocalTaskForRouteWithEmptyCache(), GenericCacheBackendUnitTestBase\testGetMultiple(), GenericCacheBackendUnitTestBase\testInvalidateAll(), GenericCacheBackendUnitTestBase\testInvalidateTags(), UrlTest\testLinkBubbleableMetadata(), ConfigEntityStorageTest\testLoad(), ConfigEntityStorageTest\testLoadMultipleAll(), ConfigEntityStorageTest\testLoadMultipleIds(), PathProcessorAliasTest\testProcessOutbound(), GenericCacheBackendUnitTestBase\testRemoveBin(), RendererPlaceholdersTest\testRenderChildrenPlaceholdersDifferentArguments(), RouteProcessorManagerTest\testRouteProcessorManager(), ConfigEntityStorageTest\testSaveChangedUuid(), GenericCacheBackendUnitTestBase\testSetGet(), UninstallTest\testUninstallPage(), CacheCollectorTest\testUpdateCache(), CacheCollectorTest\testUpdateCacheDelete(), CacheCollectorTest\testUpdateCacheMerge(), UrlGeneratorTest\testUrlGenerationWithHttpsRequirement(), ThemeRegistry\updateCache(), CacheCollector\updateCache(), TypeLinkManager\writeCache(), and RelationLinkManager\writeCache().


The documentation for this class was generated from the following file: