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
-
CacheHelper
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
protectedCounter used for counting nocache section tags.integer
-
$_match
protectedarray
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
protectedarray
Array of strings replaced in cached views. The strings are found between
<!--nocache--><!--/nocache-->
in views
Method Summary
- _enabled() protectedIs 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() protectedParse file searching for no cache tags
- _parseOutput() protectedParse 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() protectedWrite a cached version of the file
- afterLayout() publicParses the layout file and stores content for cache file building.
- afterRenderFile() publicParses the view file and stores content for cache file building.
- cache() publicMain 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
stringUpdated 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
stringwith 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
stringThe 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
stringString 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
booleansuccess 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
stringUpdated 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
stringview output
Throws
ExceptionIf debug mode is enabled and writing to cache file fails.
Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/cache.htmlProperties detail
$_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