Class CacheHelper

CacheHelper helps create full page view caching.

When using CacheHelper you don't call any of its methods, they are all automatically called by View, and use the $cacheAction settings set in the controller.

AppHelper
Extended by CacheHelper
Package: Cake\View\Helper
Link: https://book.cakephp.org/2.0/en/core-libraries/helpers/cache.html
Deprecated:

This class will be removed in 3.0. You should use a separate response cache like Varnish instead.


Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/View/Helper/CacheHelper.php

Properties summary

  • $_counter protected
    integer
    Counter used for counting nocache section tags.
  • $_match protected
    array

    Array of string that are replace with there var replace above. The strings are any content inside <!--nocache--><!--/nocache--> and includes the tags in views

  • $_replace protected
    array

    Array of strings replaced in cached views. The strings are found between <!--nocache--><!--/nocache--> in views

Method Summary

  • _enabled() protected
    Is CacheHelper enabled? should files + output be parsed.
  • _parseContent() protected

    Parse a file + output. Matches nocache tags between the current output and the current file stores a reference of the file, so the generated can be swapped back with the file contents when writing the cache file.

  • _parseFile() protected
    Parse file searching for no cache tags
  • _parseOutput() protected
    Parse the output and replace cache tags
  • _replaceSection() protected

    Munges the output from a view with cache tags, and numbers the sections. This helps solve issues with empty/duplicate content.

  • _stripTags() protected

    Strip cake:nocache tags from a string. Since View::render() only removes un-numbered nocache tags, remove all the numbered ones. This is the complement to _replaceSection.

  • _writeFile() protected
    Write a cached version of the file
  • afterLayout() public
    Parses the layout file and stores content for cache file building.
  • Parses the view file and stores content for cache file building.
  • cache() public
    Main method used to cache a view

Method Detail

_enabled()source protected

_enabled( )

Is CacheHelper enabled? should files + output be parsed.

Returns

boolean

_parseContent()source protected

_parseContent( string $file , string $out )

Parse a file + output. Matches nocache tags between the current output and the current file stores a reference of the file, so the generated can be swapped back with the file contents when writing the cache file.

Parameters

string $file
The filename to process.
string $out
The output for the file.

Returns

string
Updated content.

_parseFile()source protected

_parseFile( string $file , string $cache )

Parse file searching for no cache tags

Parameters

string $file
The filename that needs to be parsed.
string $cache
The cached content

_parseOutput()source protected

_parseOutput( string $cache )

Parse the output and replace cache tags

Parameters

string $cache
Output to replace content in.

Returns

string
with all replacements made to

_replaceSection()source protected

_replaceSection( )

Munges the output from a view with cache tags, and numbers the sections. This helps solve issues with empty/duplicate content.

Returns

string
The content with cake:nocache tags replaced.

_stripTags()source protected

_stripTags( string $content )

Strip cake:nocache tags from a string. Since View::render() only removes un-numbered nocache tags, remove all the numbered ones. This is the complement to _replaceSection.

Parameters

string $content
String to remove tags from.

Returns

string
String with tags removed.

_writeFile()source protected

_writeFile( string $content , string $timestamp , boolean|null $useCallbacks false )

Write a cached version of the file

Parameters

string $content
view content to write to a cache file.
string $timestamp
Duration to set for cache file.
boolean|null $useCallbacks optional false

Whether to include statements in cached file which run callbacks, otherwise null.

Returns

boolean
success of caching view.

afterLayout()source public

afterLayout( string $layoutFile )

Parses the layout file and stores content for cache file building.

Parameters

string $layoutFile
Layout file name.

afterRenderFile()source public

afterRenderFile( string $viewFile , string $output )

Parses the view file and stores content for cache file building.

Parameters

string $viewFile
View file name.
string $output
The output for the file.

Returns

string
Updated content.

cache()source public

cache( string $file , string $out )

Main method used to cache a view

Parameters

string $file
File to cache
string $out
output to cache

Returns

string
view output

Throws

Exception
If debug mode is enabled and writing to cache file fails.

Link

https://book.cakephp.org/2.0/en/core-libraries/helpers/cache.html

Properties detail

$_countersource

protected integer

Counter used for counting nocache section tags.

$_matchsource

protected array

Array of string that are replace with there var replace above. The strings are any content inside <!--nocache--><!--/nocache--> and includes the tags in views

array()

$_replacesource

protected array

Array of strings replaced in cached views. The strings are found between <!--nocache--><!--/nocache--> in views

array()

© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/2.10/class-CacheHelper.html