Craft 3 Class Reference

Class craft\services\TemplateCaches

Inheritance
craft\services\TemplateCaches » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/services/TemplateCaches.php

Template Caches service.

An instance of the Template Caches service is globally accessible in Craft via Craft::$app->templateCaches.

Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
deleteAllCaches() Deletes all the template caches. craft\services\TemplateCaches
deleteCacheById() Deletes a cache by its ID(s). craft\services\TemplateCaches
deleteCachesByElement() Deletes caches that include a given element(s). craft\services\TemplateCaches
deleteCachesByElementId() Deletes caches that include an a given element ID(s). craft\services\TemplateCaches
deleteCachesByElementQuery() Deletes caches that include elements that match a given element query's parameters. craft\services\TemplateCaches
deleteCachesByElementType() Deletes caches by a given element class. craft\services\TemplateCaches
deleteCachesByKey() Deletes a cache by its key(s). craft\services\TemplateCaches
deleteExpiredCaches() Deletes any expired caches. craft\services\TemplateCaches
deleteExpiredCachesIfOverdue() Deletes any expired caches if we haven't already done that within the past 24 hours. craft\services\TemplateCaches
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
endTemplateCache() Ends a template cache. craft\services\TemplateCaches
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getTemplateCache() Returns a cached template by its key. craft\services\TemplateCaches
handleResponse() Queues up a Delete Stale Template Caches job craft\services\TemplateCaches
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
includeElementInTemplateCaches() Includes an element in any active caches. craft\services\TemplateCaches
includeElementQueryInTemplateCaches() Includes an element criteria in any active caches. craft\services\TemplateCaches
init() Initializes the object. yii\base\BaseObject
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
startTemplateCache() Starts a new template cache. craft\services\TemplateCaches
trigger() Triggers an event. yii\base\Component

Method Details

deleteAllCaches() public method #

Deletes all the template caches.

public boolean deleteAllCaches ( )

deleteCacheById() public method #

Deletes a cache by its ID(s).

public boolean deleteCacheById ( $cacheId )
$cacheId integer, array The cache ID.

deleteCachesByElement() public method #

Deletes caches that include a given element(s).

public boolean deleteCachesByElement ( $elements )
$elements craft\base\ElementInterface, craft\base\ElementInterface[] The element(s) whose caches should be deleted.

deleteCachesByElementId() public method #

Deletes caches that include an a given element ID(s).

public boolean deleteCachesByElementId ( $elementId, \craft\services\bool $deleteQueryCaches true )
$elementId integer, integer[] The ID of the element(s) whose caches should be cleared.
$deleteQueryCaches boolean Whether a DeleteStaleTemplateCaches job should be added to the queue, deleting any query caches that may now involve this element, but hadn't previously. (Defaults to true.)

deleteCachesByElementQuery() public method #

Deletes caches that include elements that match a given element query's parameters.

public boolean deleteCachesByElementQuery ( craft\elements\db\ElementQuery $query )
$query craft\elements\db\ElementQuery The element query that should be used to find elements whose caches should be deleted.

deleteCachesByElementType() public method #

Deletes caches by a given element class.

public boolean deleteCachesByElementType ( \craft\services\string $elementType )
$elementType string The element class.

deleteCachesByKey() public method #

Deletes a cache by its key(s).

public boolean deleteCachesByKey ( $key )
$key integer, array The cache key(s) to delete.

deleteExpiredCaches() public method #

Deletes any expired caches.

public boolean deleteExpiredCaches ( )

deleteExpiredCachesIfOverdue() public method #

Deletes any expired caches if we haven't already done that within the past 24 hours.

public boolean deleteExpiredCachesIfOverdue ( )

endTemplateCache() public method #

Ends a template cache.

public void endTemplateCache ( \craft\services\string $key, \craft\services\bool $global, \craft\services\string $duration null, $expiration, \craft\services\string $body )
$key string The template cache key.
$global boolean Whether the cache should be stored globally.
$duration string, null How long the cache should be stored for. Should be a relative time format.
$expiration mixed, null When the cache should expire.
$body string The contents of the cache.
throws Throwable

getTemplateCache() public method #

Returns a cached template by its key.

public string, null getTemplateCache ( \craft\services\string $key, \craft\services\bool $global )
$key string The template cache key
$global boolean Whether the cache would have been stored globally.

handleResponse() public method #

Queues up a Delete Stale Template Caches job

public void handleResponse ( )

includeElementInTemplateCaches() public method #

Includes an element in any active caches.

public void includeElementInTemplateCaches ( \craft\services\int $elementId )
$elementId integer The element ID.

includeElementQueryInTemplateCaches() public method #

Includes an element criteria in any active caches.

public void includeElementQueryInTemplateCaches ( yii\base\Event $event )
$event yii\base\Event The 'afterPrepare' element query event

startTemplateCache() public method #

Starts a new template cache.

public void startTemplateCache ( \craft\services\string $key )
$key string The template cache key.