TemplateCaches
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\TemplateCaches » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
- Implements
- yii\base\Configurable (opens new window)
- Since
- 3.0.0
Template Caches service.
An instance of the service is available via Craft::$app->templateCaches
.
View source (opens new window)
# Public Properties
Property | Description |
---|---|
behaviors (opens new window) | yii\base\Behavior (opens new window) – List of behaviors attached to this component. |
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__clone() (opens new window) | This method is called after the object is created by cloning an existing one. |
__construct() (opens new window) | Constructor. |
__get() (opens new window) | Returns the value of a component property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__set() (opens new window) | Sets the value of a component property. |
__unset() (opens new window) | Sets a component property to be null. |
attachBehavior() (opens new window) | Attaches a behavior to this component. |
attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
behaviors() (opens new window) | Returns a list of behaviors that this component should behave as. |
canGetProperty() (opens new window) | Returns a value indicating whether a property can be read. |
canSetProperty() (opens new window) | Returns a value indicating whether a property can be set. |
className() (opens new window) | Returns the fully qualified name of this class. |
deleteAllCaches() | Deletes all the template caches. |
deleteCacheById() | Deletes a cache by its ID(s). |
deleteCachesByElement() | Deletes caches that include a given element(s). |
deleteCachesByElementId() | Deletes caches that include an a given element ID(s). |
deleteCachesByElementQuery() | Deletes caches that include elements that match a given element query's parameters. |
deleteCachesByElementType() | Deletes caches by a given element class. |
deleteCachesByKey() | Deletes a cache by its key(s). |
deleteExpiredCaches() | Deletes any expired caches. |
deleteExpiredCachesIfOverdue() | Deletes any expired caches. |
detachBehavior() (opens new window) | Detaches a behavior from the component. |
detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
endTemplateCache() | Ends a template cache. |
ensureBehaviors() (opens new window) | Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component. |
getBehavior() (opens new window) | Returns the named behavior object. |
getBehaviors() (opens new window) | Returns all behaviors attached to this component. |
getTemplateCache() | Returns a cached template by its key. |
handleResponse() | Queues up a Delete Stale Template Caches job |
hasEventHandlers() (opens new window) | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() (opens new window) | Returns a value indicating whether a method is defined. |
hasProperty() (opens new window) | Returns a value indicating whether a property is defined for this component. |
includeElementInTemplateCaches() | Includes an element in any active caches. |
includeElementQueryInTemplateCaches() | Includes an element criteria in any active caches. |
init() (opens new window) | Initializes the object. |
off() (opens new window) | Detaches an existing event handler from this component. |
on() (opens new window) | Attaches an event handler to an event. |
startTemplateCache() | Starts a new template cache. |
trigger() (opens new window) | Triggers an event. |
# deleteAllCaches()
DEPRECATED
Deprecated in 3.5.0. Use craft\services\Elements::invalidateAllCaches() instead.
Deletes all the template caches.
View source (opens new window)
Returns
# deleteCacheById()
DEPRECATED
Deprecated in 3.5.0
Deletes a cache by its ID(s).
View source (opens new window)
Arguments
$cacheId
(integer (opens new window), integer (opens new window)[]) – The cache ID(s)
Returns
# deleteCachesByElement()
DEPRECATED
Deprecated in 3.5.0. Use craft\services\Elements::invalidateCachesForElement() instead.
Deletes caches that include a given element(s).
View source (opens new window)
Arguments
$elements
(craft\base\ElementInterface, craft\base\ElementInterface[]) – The element(s) whose caches should be deleted.
Returns
# deleteCachesByElementId()
DEPRECATED
Deprecated in 3.5.0. Use craft\services\Elements::invalidateCachesForElement() instead.
Deletes caches that include an a given element ID(s).
View source (opens new window)
Arguments
$elementId
(integer (opens new window), integer (opens new window)[]) – The ID of the element(s) whose caches should be cleared.$deleteQueryCaches
(boolean (opens new window)) – 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 totrue
.)
Returns
# deleteCachesByElementQuery()
DEPRECATED
Deprecated in 3.5.0. Use craft\services\Elements::invalidateCachesForElementType() instead.
Deletes caches that include elements that match a given element query's parameters.
View source (opens new window)
Arguments
$query
(craft\elements\db\ElementQuery) – The element query that should be used to find elements whose caches should be deleted.
Returns
# deleteCachesByElementType()
DEPRECATED
Deprecated in 3.5.0. Use craft\services\Elements::invalidateCachesForElementType() instead.
Deletes caches by a given element class.
View source (opens new window)
Arguments
$elementType
(string (opens new window)) – The element class.
Returns
# deleteCachesByKey()
Deletes a cache by its key(s).
View source (opens new window)
Arguments
$key
(string (opens new window), string (opens new window)[]) – The cache key(s) to delete.$global
(boolean (opens new window), null (opens new window)) – Whether the template caches are stored globally.$siteId
(integer (opens new window), null (opens new window)) – The site ID to delete caches for.
Returns
Throws
- yii\base\Exception (opens new window)
if this is a console request andnull
orfalse
is passed to$global
# deleteExpiredCaches()
DEPRECATED
Deprecated in 3.5.0
Deletes any expired caches.
View source (opens new window)
Returns
# deleteExpiredCachesIfOverdue()
DEPRECATED
Deprecated in 3.2.0
Deletes any expired caches.
View source (opens new window)
Returns
# endTemplateCache()
Ends a template cache.
View source (opens new window)
Arguments
$key
(string (opens new window)) – The template cache key.$global
(boolean (opens new window)) – Whether the cache should be stored globally.$duration
(string (opens new window), null (opens new window)) – How long the cache should be stored for. Should be a relative time format (opens new window).$expiration
(mixed
, null (opens new window)) – When the cache should expire.$body
(string (opens new window)) – The contents of the cache.$withScripts
(boolean (opens new window)) – Whether JS and CSS code registered with craft\web\View::registerJs(), craft\web\View::registerScript(), and craft\web\View::registerCss() (opens new window) should be captured and included in the cache.
Throws
- yii\base\Exception (opens new window)
if this is a console request andfalse
is passed to$global
- Throwable (opens new window)
# getTemplateCache()
Returns a cached template by its key.
View source (opens new window)
Arguments
$key
(string (opens new window)) – The template cache key$global
(boolean (opens new window)) – Whether the cache would have been stored globally.$registerScripts
(boolean (opens new window)) – Whether JS and CSS code coptured with the cache should be registered
Returns
string (opens new window), null (opens new window)
Throws
- yii\base\Exception (opens new window)
if this is a console request andfalse
is passed to$global
# handleResponse()
DEPRECATED
Deprecated in 3.5.0
Queues up a Delete Stale Template Caches job
View source (opens new window)
# includeElementInTemplateCaches()
DEPRECATED
Deprecated in 3.5.0
Includes an element in any active caches.
View source (opens new window)
Arguments
$elementId
(integer (opens new window)) – The element ID.
# includeElementQueryInTemplateCaches()
DEPRECATED
Deprecated in 3.5.0
Includes an element criteria in any active caches.
View source (opens new window)
Arguments
$event
(yii\base\Event (opens new window)) – The 'afterPrepare' element query event
# startTemplateCache()
Starts a new template cache.
View source (opens new window)
Arguments
$withScripts
(boolean (opens new window)) – Whether JS and CSS code registered with craft\web\View::registerJs(), craft\web\View::registerScript(), and craft\web\View::registerCss() (opens new window) should be captured and included in the cache. If this istrue
, be sure to pass$withScripts = true
to endTemplateCache() as well.$global
(boolean (opens new window)) – Whether the cache should be stored globally.
# Events
# EVENT_AFTER_DELETE_CACHES
DEPRECATED
Deprecated in 3.5.0
- Type
craft\services\SectionEvent
- Since
- 3.0.2
The event that is triggered after template caches are deleted.
# EVENT_BEFORE_DELETE_CACHES
DEPRECATED
Deprecated in 3.5.0
- Type
craft\services\SectionEvent
- Since
- 3.0.2
The event that is triggered before template caches are deleted.