Skip to content

Commit

Permalink
Add information about configuring Redis cache (#2058)
Browse files Browse the repository at this point in the history
* Add information about configuring Redis cache

Information and an example is added for
configuring Redis cache.

* Update Index.rst

- Remove warning box

Co-authored-by: Tom Warwick <tom.warwick@typo3.org>
  • Loading branch information
sypets and tomwarwick committed Aug 15, 2022
1 parent e7f9df4 commit f5e15db
Showing 1 changed file with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,73 @@ which must be available on the system.
contains some important hints on how to speed up the system if it reaches bounds.
A full documentation of available options is far beyond this documentation.


.. _caching-backend-redis-example:

Redis example
-------------

The Redis caching backend configuration is very similar to that of other
backends, but there is one caveat.

TYPO3 caches should be separated in case the same keys are used.
This applies to the `pages` and `pagesection` caches.
Both use "tagIdents:pageId_21566" for a page with an id of 21566.
How you separate them is more of a system administrator decision. We provide
examples with several databases but this may not be the best option
in production where you might want to use multiple cores (which do not
support databases). The separation has the additional advantage that
caches can be flushed individually.

If you have several of your own caches which each use unique keys (for example
by using a different prefix for the cache identifier for each cache), you can
store them in the same database, but it is good practice to separate the core
caches.

.. intentional quote!
In practical terms, Redis databases should be used to separate different keys
belonging to the same application (if needed), and not to use a single Redis
instance for multiple unrelated applications.
https://redis.io/commands/select/
.. code-block:: php
:caption: public/typo3conf/AdditionalConfiguration.php
$redisHost = '127.0.0.1';
$redisPort = 6390;
$redisCaches = [
'pages' => [
'defaultLifetime' => 86400*7,
'compression' => true,
],
'pagesection' => [
'defaultLifetime' => 86400*7,
],
'hash' => [],
'rootline' => [],
];
$redisDatabase = 0;
foreach ($redisCaches as $name => $values) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$name]['backend']
= \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$name]['options'] = [
'database' => $redisDatabase++,
'hostname' => $redisHost,
'port' => $redisPort
];
if (isset($values['defaultLifetime'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$name]['options']['defaultLifetime']
= $values['lifetime'];
}
if (isset($values['compression'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$name]['options']['compression']
= $values['compression'];
}
}
.. _caching-backend-redis-options:

Options
Expand Down

0 comments on commit f5e15db

Please sign in to comment.