.. _Cache: ============================================== Cache ============================================== \\nn\\t3::Cache() ---------------------------------------------- Methods for reading and writing to the Typo3 cache. Uses the Typo3 caching framework, see ``EXT:nnhelpers/ext_localconf.php`` for details Overview of Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\nn\\t3::Cache()->clear(``$identifier = NULL``); """"""""""""""""""""""""""""""""""""""""""""""" Deletes caches. If an ``identifier`` is specified, only the caches of the specific identifier are deleted identifier are deleted â otherwise ALL caches of all extensions and pages. RAM caches CachingFramework caches that were set via ``\nn\t3::Cache()->set()`` File caches that were set via ``\nn\t3::Cache()->write()`` .. code-block:: php // delete ALL caches â also the caches of other extensions, pages etc. \nn\t3::Cache()->clear(); // Delete only the caches with a specific identifier \nn\t3::Cache()->clear('nnhelpers'); | ``@param string $identifier`` | ``@return void`` | :ref:`➜ Go to source code of Cache::clear() ` \\nn\\t3::Cache()->clearPageCache(``$pid = NULL``); """"""""""""""""""""""""""""""""""""""""""""""" Deletes the page cache. Alias to ``\nn\t3::Page()->clearCache()`` .. code-block:: php \nn\t3::Cache()->clearPageCache( 17 ); // Delete page cache for pid=17 \nn\t3::Cache()->clearPageCache(); // clear cache of ALL pages | ``@param mixed $pid`` pid of the page whose cache is to be cleared or leave empty for all pages | ``@return void`` | :ref:`➜ Go to source code of Cache::clearPageCache() ` \\nn\\t3::Cache()->get(``$identifier = '', $useRamCache = false``); """"""""""""""""""""""""""""""""""""""""""""""" Reads the content of the Typo3 cache using an identifier. The identifier is any string or array that uniquely identifies the cache. .. code-block:: php \nn\t3::Cache()->get('myid'); \nn\t3::Cache()->get(['pid'=>1, 'uid'=>'7']); \nn\t3::Cache()->get(['func'=>__METHOD__, 'uid'=>'17']); \nn\t3::Cache()->get([__METHOD__=>$this->request->getArguments()]); | ``@param mixed $identifier`` String or array to identify the cache | ``@param mixed $useRamCache`` temporary cache in $GLOBALS instead of caching framework | ``@return mixed`` | :ref:`➜ Go to source code of Cache::get() ` \\nn\\t3::Cache()->getIdentifier(``$identifier = NULL``); """"""""""""""""""""""""""""""""""""""""""""""" Converts transferred cache identifiers into a usable string. Can also process an array as identifier. | ``@param mixed $indentifier`` | ``@return string`` | :ref:`➜ Go to source code of Cache::getIdentifier() ` \\nn\\t3::Cache()->read(``$identifier``); """"""""""""""""""""""""""""""""""""""""""""""" Read static file cache. Reads the PHP file that was written via ``\nn\t3::Cache()->write()``. .. code-block:: php $cache = \nn\t3::Cache()->read( $identifier ); The PHP file is an executable PHP script with the ``return command`` It stores the cache content in an array. .. code-block:: php ...]; | ``@return string|array`` | :ref:`➜ Go to source code of Cache::read() ` \\nn\\t3::Cache()->set(``$identifier = '', $data = NULL, $useRamCache = false``); """"""""""""""""""""""""""""""""""""""""""""""" Writes an entry to the Typo3 cache. The identifier is an arbitrary string or an array that uniquely identifies the cache. .. code-block:: php // Classic application in the controller: Get and set cache if ($cache = \nn\t3::Cache()->get('myid')) return $cache; ... $cache = $this->view->render(); return \nn\t3::Cache()->set('myid', $cache); .. code-block:: php // Use RAM cache? Set TRUE as the third parameter \nn\t3::Cache()->set('myid', $dataToCache, true); // Set the duration of the cache to 60 minutes \nn\t3::Cache()->set('myid', $dataToCache, 3600); // An array can also be specified as the key \nn\t3::Cache()->set(['pid'=>1, 'uid'=>'7'], $html); | ``@param mixed $indentifier`` String or array to identify the cache | ``@param mixed $data`` Data to be written to the cache. (string or array) | ``@param mixed $useRamCache`` ``true``: temporary cache in $GLOBALS instead of caching framework. | ``integer``: How many seconds to cache? | ``@return mixed`` | :ref:`➜ Go to source code of Cache::set() ` \\nn\\t3::Cache()->write(``$identifier, $cache``); """"""""""""""""""""""""""""""""""""""""""""""" Write static file cache. Writes a PHP file that can be loaded via ``$cache = require('...')``. Based on many core functions and extensions (e.g. mask), which place static PHP files into the file system in order to better cache performance-intensive processes such as class paths, annotation parsing etc. better. Deliberately do not use the core functions in order to avoid any overhead and and to ensure the greatest possible compatibility with core updates. .. code-block:: php $cache = ['a'=>1, 'b'=>2]; $identifier = 'myid'; \nn\t3::Cache()->write( $identifier, $cache ); $read = \nn\t3::Cache()->read( $identifier ); The example above generates a PHP file with this content: .. code-block:: php ['a'=>1, 'b'=>2]]; | ``@return string|array`` | :ref:`➜ Go to source code of Cache::write() ` Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. toctree:: :glob: :maxdepth: 1 *