From 04c368b9c9ff5c9667e930351ffe5dd488bb57c2 Mon Sep 17 00:00:00 2001 From: fakela Date: Sun, 21 Jan 2024 00:41:32 +0000 Subject: [PATCH 01/18] add cache docs --- docs/components/cache.rst | 103 ++++++++++++++++++++++++++ docs/links/symfony_cache_component.py | 7 ++ 2 files changed, 110 insertions(+) create mode 100644 docs/links/symfony_cache_component.py diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 035d80c7..90fb1fd3 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -1,4 +1,107 @@ Cache ##### +Symfony makes heavy use of a filesystem cache. When developing for Mautic, clearing the cache is a regular occurrence. By default, Mautic instances have the cache located in ``var/cache/ENV`` where ``ENV`` is the environment currently accessed (``dev`` or ``prod``). To rebuild the cache, delete the relevant ``ENV`` folder within the cache directory, or run the Symfony command ``php bin/console cache:clear --env=ENV``. If a specific environment isn't passed to the command via ``--env=ENV``, Mautic uses the ``dev`` environment by default. + +In the ``dev`` environment, Mautic doesn't cache translations, views, and Assets. However, changes to these files require clearing the cache for them to take effect in the ``prod`` environment. Changes to Mautic config files, Symfony config files, etc., require clearing of the cache regardless of the environment. + +The typical rule of thumb is, if Mautic isn't acting as you expect after making changes, try clearing your cache. If you get ``class could not be found`` or ``cannot redeclare class`` errors when using the ``cache:clear`` command, manually delete the ``var/cache/ENV`` folder then run the command and/or browse to the site to rebuild. + +Cache bundle +************ + +Enables PSR-6 and PSR-16 caching. Check :xref:`Symfony Cache Component` + +Namespace versus tag +==================== + +This bundle introduces tags to the cache. All its adapters are fully tag aware which makes the use of namespace obsolete for daily use. + +Previously, if you wanted to keep control on cache section and didn't want to hold the index of all keys to clear, you would have to use namespace. + +The main disadvantage of this approach is that Mautic creates a new adapter for each namespace. + +From Symfony 3.4, the cache uses tag-aware adapters. If you want to clear all records related to your Bundle or Component, you just need to tag them. + +.. code-block:: php + /** @var CacheProvider $cache */ + $cache = $this->get('mautic.cache.provider'); + /** @var CacheItemInterface $item */ + $item = $cache->getItem('test_tagged_Item'); + $item->set('yesa!!!'); + $item->tag(['firstTag', 'secondTag']); + $item->expiresAfter(20000); +All you need to do now is to clear all tagged items: + +.. code-block:: php + $cache->invalidateTags(['firstTag']); +Pools clearing +============== + +Removing cache items +-------------------- + +Cache Pools include methods to delete a cache item, some of them, or all of them. The most common is ``Psr\\Cache\\CacheItemPoolInterface::deleteItem``, which deletes the cache item identified by the given key. + +.. code-block:: php + $isDeleted = $cache->deleteItem('user_'.$userId); +Use the ``Psr\\Cache\\CacheItemPoolInterface::deleteItems`` method to delete several cache items simultaneously - it returns true only if all the items have been deleted, even when any or some of them don't exist: + +Configuration +------------- + +Plugins come preconfigured to utilize filesystem caching. + +These are the default settings: + +.. code-block:: php + 'cache_adapter' => 'mautic.cache.adapter.filesystem', + 'cache_prefix' => 'app', + 'cache_lifetime' => 86400 +They can be overridden in ``local.php`` like this: + +.. code-block:: php + 'cache_adapter' => 'mautic.cache.adapter.redis', + 'cache_prefix' => 'app_cache', + 'cache_lifetime' => 86400, +Delivered adapters +------------------ + +- ``mautic.cache.adapter.filesystem`` +- ``mautic.cache.adapter.memcached`` + +.. code-block:: php + 'memcached' => [ + 'servers' => ['memcached://localhost'], + 'options' => [ + 'compression' => true, + 'libketama_compatible' => true, + 'serializer' => 'igbinary', + ], + ], +- ``mautic.cache.adapter.redis`` + +Redis configuration in ``local.php``: + +.. code-block:: php + 'redis' => [ + 'dsn' => 'redis://localhost', + 'options' => [ + 'lazy' => false, + 'persistent' => 0, + 'persistent_id' => null, + 'timeout' => 30, + 'read_timeout' => 0, + 'retry_interval' => 0, + ], + ], +In order to use another adapter, just set it up as a service. + +Clearing the cache +------------------ + +When the ``cache:clear`` command is run, Mautic's cache is cleared. The cache can be cleared by running: + +.. code-block:: bash + bin/console mautic:cache:clear diff --git a/docs/links/symfony_cache_component.py b/docs/links/symfony_cache_component.py new file mode 100644 index 00000000..2a06aae1 --- /dev/null +++ b/docs/links/symfony_cache_component.py @@ -0,0 +1,7 @@ +from . import link + +link_name = "Symfony Cache Component" +link_text = "Symfony Cache Component" +link_url = "https://symfony.com/doc/current/components/cache.html" + +link.xref_links.update({link_name: (link_text, link_url)}) \ No newline at end of file From 0a7b635bd88abdfbc16e758cde83f089d9cfe4e5 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Mon, 12 Feb 2024 15:34:11 +0100 Subject: [PATCH 02/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 90fb1fd3..6c12213c 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -3,7 +3,12 @@ Cache Symfony makes heavy use of a filesystem cache. When developing for Mautic, clearing the cache is a regular occurrence. By default, Mautic instances have the cache located in ``var/cache/ENV`` where ``ENV`` is the environment currently accessed (``dev`` or ``prod``). To rebuild the cache, delete the relevant ``ENV`` folder within the cache directory, or run the Symfony command ``php bin/console cache:clear --env=ENV``. If a specific environment isn't passed to the command via ``--env=ENV``, Mautic uses the ``dev`` environment by default. -In the ``dev`` environment, Mautic doesn't cache translations, views, and Assets. However, changes to these files require clearing the cache for them to take effect in the ``prod`` environment. Changes to Mautic config files, Symfony config files, etc., require clearing of the cache regardless of the environment. + +.. vale off + +In the ``dev`` environment, Mautic doesn't cache translations, views, and assets. However, changes to these files require clearing the cache for them to take effect in the ``prod`` environment. Changes to Mautic config files, Symfony config files, etc., require clearing of the cache regardless of the environment. + +.. vale on The typical rule of thumb is, if Mautic isn't acting as you expect after making changes, try clearing your cache. If you get ``class could not be found`` or ``cannot redeclare class`` errors when using the ``cache:clear`` command, manually delete the ``var/cache/ENV`` folder then run the command and/or browse to the site to rebuild. From 0ea764076861cb4ad9618ee4df733ec4ef043159 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Mon, 12 Feb 2024 15:34:52 +0100 Subject: [PATCH 03/18] Update docs/components/cache.rst Co-authored-by: Rohit Joshi --- docs/components/cache.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 6c12213c..78bfe5a7 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -50,7 +50,7 @@ Cache Pools include methods to delete a cache item, some of them, or all of them .. code-block:: php $isDeleted = $cache->deleteItem('user_'.$userId); -Use the ``Psr\\Cache\\CacheItemPoolInterface::deleteItems`` method to delete several cache items simultaneously - it returns true only if all the items have been deleted, even when any or some of them don't exist: +Use the ``Psr\\Cache\\CacheItemPoolInterface::deleteItems`` method to delete several cache items simultaneously - it returns true only if all the items have been deleted, even when any or some of them don't exist. Configuration ------------- From 2f8434f3975f4ac1246fa1f2fe6299451dee1597 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 09:41:24 +0100 Subject: [PATCH 04/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 78bfe5a7..6fb03207 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -29,6 +29,7 @@ The main disadvantage of this approach is that Mautic creates a new adapter for From Symfony 3.4, the cache uses tag-aware adapters. If you want to clear all records related to your Bundle or Component, you just need to tag them. .. code-block:: php + /** @var CacheProvider $cache */ $cache = $this->get('mautic.cache.provider'); /** @var CacheItemInterface $item */ From 72e06addd2399b63588f37413ade341a87851360 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 09:41:35 +0100 Subject: [PATCH 05/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 6fb03207..3f50a9bb 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -10,7 +10,7 @@ In the ``dev`` environment, Mautic doesn't cache translations, views, and assets .. vale on -The typical rule of thumb is, if Mautic isn't acting as you expect after making changes, try clearing your cache. If you get ``class could not be found`` or ``cannot redeclare class`` errors when using the ``cache:clear`` command, manually delete the ``var/cache/ENV`` folder then run the command and/or browse to the site to rebuild. +The typical rule of thumb is, if Mautic isn't acting as you expect after making changes, try clearing your cache. If you get ``class could not be found`` or ``cannot redeclare class`` errors when using the ``cache:clear`` command, manually delete the ``var/cache/ENV`` folder - replacing ENV with the environment eg ``dev`` or ``prod`` - then run the command and/or browse to the site to rebuild. Cache bundle ************ From 6c079d84edef56ad8d0eb599243d3b1de20fcc00 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 09:41:42 +0100 Subject: [PATCH 06/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 3f50a9bb..46d05a24 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -1,7 +1,7 @@ Cache ##### -Symfony makes heavy use of a filesystem cache. When developing for Mautic, clearing the cache is a regular occurrence. By default, Mautic instances have the cache located in ``var/cache/ENV`` where ``ENV`` is the environment currently accessed (``dev`` or ``prod``). To rebuild the cache, delete the relevant ``ENV`` folder within the cache directory, or run the Symfony command ``php bin/console cache:clear --env=ENV``. If a specific environment isn't passed to the command via ``--env=ENV``, Mautic uses the ``dev`` environment by default. +Symfony makes heavy use of a filesystem cache. When developing for Mautic, clearing the cache is a regular occurrence. By default, Mautic instances have the cache located in ``var/cache/ENV`` where ``ENV`` is the environment currently accessed - ``dev`` or ``prod``. To rebuild the cache, delete the relevant ``ENV`` folder within the cache directory, or run the Symfony command ``php bin/console cache:clear --env=ENV``. If a specific environment isn't passed to the command via ``--env=ENV``, Mautic uses the ``dev`` environment by default. .. vale off From 67b70b33e1add92127063075f85b59e46978e2ff Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 09:41:55 +0100 Subject: [PATCH 07/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 46d05a24..d3245f91 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -37,6 +37,7 @@ From Symfony 3.4, the cache uses tag-aware adapters. If you want to clear all re $item->set('yesa!!!'); $item->tag(['firstTag', 'secondTag']); $item->expiresAfter(20000); + All you need to do now is to clear all tagged items: .. code-block:: php From 4f447fa6845c0827dc3ecbc866ea953ac90f0092 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 09:42:16 +0100 Subject: [PATCH 08/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index d3245f91..6b2a89e7 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -41,6 +41,7 @@ From Symfony 3.4, the cache uses tag-aware adapters. If you want to clear all re All you need to do now is to clear all tagged items: .. code-block:: php + $cache->invalidateTags(['firstTag']); Pools clearing ============== From 1ba62f3150c8d69c03cda49ec1490f799375d976 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 09:42:27 +0100 Subject: [PATCH 09/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 6b2a89e7..36ba323f 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -87,6 +87,7 @@ Delivered adapters 'serializer' => 'igbinary', ], ], + - ``mautic.cache.adapter.redis`` Redis configuration in ``local.php``: From d84905d5f173cad2b1f985270afea6f5d773859f Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 09:45:58 +0100 Subject: [PATCH 10/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 36ba323f..1181167b 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -52,6 +52,7 @@ Removing cache items Cache Pools include methods to delete a cache item, some of them, or all of them. The most common is ``Psr\\Cache\\CacheItemPoolInterface::deleteItem``, which deletes the cache item identified by the given key. .. code-block:: php + $isDeleted = $cache->deleteItem('user_'.$userId); Use the ``Psr\\Cache\\CacheItemPoolInterface::deleteItems`` method to delete several cache items simultaneously - it returns true only if all the items have been deleted, even when any or some of them don't exist. From 6e569f5582f5c1833e5efd24d00afad6491fe2f8 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 09:46:52 +0100 Subject: [PATCH 11/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 1181167b..c42fa776 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -64,6 +64,7 @@ Plugins come preconfigured to utilize filesystem caching. These are the default settings: .. code-block:: php + 'cache_adapter' => 'mautic.cache.adapter.filesystem', 'cache_prefix' => 'app', 'cache_lifetime' => 86400 From 8f2eb4908f4d1b64839861c81a6d9cca7660ebed Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 09:53:35 +0100 Subject: [PATCH 12/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index c42fa776..b279ca17 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -95,6 +95,7 @@ Delivered adapters Redis configuration in ``local.php``: .. code-block:: php + 'redis' => [ 'dsn' => 'redis://localhost', 'options' => [ From 8870b3b91db96271118fa5d5004a9e83e7d8ff75 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 10:01:35 +0100 Subject: [PATCH 13/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index b279ca17..5d7dc002 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -71,6 +71,7 @@ These are the default settings: They can be overridden in ``local.php`` like this: .. code-block:: php + 'cache_adapter' => 'mautic.cache.adapter.redis', 'cache_prefix' => 'app_cache', 'cache_lifetime' => 86400, From 3b79b96b5841d245a40247ea6230610149ed1912 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 10:02:24 +0100 Subject: [PATCH 14/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 5d7dc002..49a2dd04 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -75,6 +75,7 @@ They can be overridden in ``local.php`` like this: 'cache_adapter' => 'mautic.cache.adapter.redis', 'cache_prefix' => 'app_cache', 'cache_lifetime' => 86400, + Delivered adapters ------------------ From 675286c8d5f777990d6e8023d976f69c94980e6b Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 10:02:34 +0100 Subject: [PATCH 15/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 49a2dd04..b2fc5647 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -109,6 +109,7 @@ Redis configuration in ``local.php``: 'retry_interval' => 0, ], ], + In order to use another adapter, just set it up as a service. Clearing the cache From bd3722a7104694facb04b16e9c7329c08dd4f4c3 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Fri, 16 Feb 2024 10:02:52 +0100 Subject: [PATCH 16/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index b2fc5647..20eea735 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -115,7 +115,7 @@ In order to use another adapter, just set it up as a service. Clearing the cache ------------------ -When the ``cache:clear`` command is run, Mautic's cache is cleared. The cache can be cleared by running: +The ``cache:clear`` command clears Mautic's cache. Use this command: .. code-block:: bash bin/console mautic:cache:clear From 8e9ecd42416958ef2a99f23fca6fda496a3c3ff9 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Sat, 17 Feb 2024 13:20:03 +0100 Subject: [PATCH 17/18] Update docs/components/cache.rst Co-authored-by: Ruth Cheesley --- docs/components/cache.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 20eea735..7b793037 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -118,5 +118,6 @@ Clearing the cache The ``cache:clear`` command clears Mautic's cache. Use this command: .. code-block:: bash + bin/console mautic:cache:clear From a438c6843d36aa5d3f70f995a5c69dbbb551e610 Mon Sep 17 00:00:00 2001 From: Favour Kelvin Date: Mon, 4 Mar 2024 15:55:45 +0000 Subject: [PATCH 18/18] update cache docs --- docs/components/cache.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/components/cache.rst b/docs/components/cache.rst index 7b793037..326c6966 100644 --- a/docs/components/cache.rst +++ b/docs/components/cache.rst @@ -10,7 +10,7 @@ In the ``dev`` environment, Mautic doesn't cache translations, views, and assets .. vale on -The typical rule of thumb is, if Mautic isn't acting as you expect after making changes, try clearing your cache. If you get ``class could not be found`` or ``cannot redeclare class`` errors when using the ``cache:clear`` command, manually delete the ``var/cache/ENV`` folder - replacing ENV with the environment eg ``dev`` or ``prod`` - then run the command and/or browse to the site to rebuild. +The typical rule of thumb is, if Mautic isn't acting as you expect after making changes, try clearing your cache. If you get ``class could not be found`` or ``cannot redeclare class`` errors when using the ``cache:clear`` command, manually delete the ``var/cache/ENV`` folder - replacing ENV with the environment e.g ``dev`` or ``prod`` - then run the command and/or browse to the site to rebuild. Cache bundle ************ @@ -78,6 +78,7 @@ They can be overridden in ``local.php`` like this: Delivered adapters ------------------ +.. vale off - ``mautic.cache.adapter.filesystem`` - ``mautic.cache.adapter.memcached``