From 7fc0616362194fcadd583b3be4baeddb3cb4a736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20R?= Date: Thu, 23 Aug 2018 09:47:32 +0200 Subject: [PATCH] [YML] Add default cache prefix in order to share cache across cluster (#313) Overrides the default cache namespace: https://github.com/symfony/symfony/blob/3.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php#L33-L38 This makes sure cache is shared across a cluster no matter what the path of install is used or what Symfony Env you are using, hence making sure changes done on a dev env is affecting prod as well. if install uses different DBs then inline doc here implies separate namespace should be used, or user should opt for default behavior instead where it would vary by cache service as it's part of prefix seed. --- app/config/cache_pool/cache.memcached.yml | 7 +++++++ app/config/cache_pool/cache.redis.yml | 7 +++++++ app/config/default_parameters.yml | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/app/config/cache_pool/cache.memcached.yml b/app/config/cache_pool/cache.memcached.yml index dfdf310e38..615b2a4af8 100644 --- a/app/config/cache_pool/cache.memcached.yml +++ b/app/config/cache_pool/cache.memcached.yml @@ -8,3 +8,10 @@ services: # Example from vendor/symfony/symfony/src/Symfony/Component/Cache/Traits/MemcachedTrait.php: # memcached://user:pass@localhost?weight=33' provider: 'memcached://%cache_dsn%' + # Cache namespace prefix overriding the one used by Symfony globally + # This makes sure cache is reliably shared across whole cluster and all Symfony env's + # Can be used for blue/green deployment strategies when changes affect content cache. + # For multi db setup adapt this to be unique per pool (one pool per database) + # If you prefer default behaviour set this to null or comment out, and consider for instance: + # https://symfony.com/doc/current/reference/configuration/framework.html#prefix-seed + namespace: '%cache_namespace%' diff --git a/app/config/cache_pool/cache.redis.yml b/app/config/cache_pool/cache.redis.yml index 3b079d9907..6a950f44ab 100644 --- a/app/config/cache_pool/cache.redis.yml +++ b/app/config/cache_pool/cache.redis.yml @@ -10,3 +10,10 @@ services: # redis://secret@example.com:1234/13 # redis://secret@/var/run/redis.sock/13?persistent_id=4&class=Redis&timeout=3&retry_interval=3 provider: 'redis://%cache_dsn%' + # Cache namespace prefix overriding the one used by Symfony by default + # This makes sure cache is reliably shared across whole cluster and all Symfony env's + # Can be used for blue/green deployment strategies when changes affect content cache. + # For multi db setup adapt this to be unique per pool (one pool per database) + # If you prefer default behaviour set this to null or comment out, and consider for instance: + # https://symfony.com/doc/current/reference/configuration/framework.html#prefix-seed + namespace: '%cache_namespace%' diff --git a/app/config/default_parameters.yml b/app/config/default_parameters.yml index 8b23cfbea0..366963e87f 100644 --- a/app/config/default_parameters.yml +++ b/app/config/default_parameters.yml @@ -35,6 +35,10 @@ parameters: # Cache DSN, see app/config/services/cache.yml for examples: cache_dsn: '%env(CACHE_DSN)%' + + # Cache namespace prefix for use with Redis/Memcached, 'ez' by default. + # For further info incl alternatives for "blue/green deployment" and multi repo installs, see: app/config/cache_pool/*.yml + cache_namespace: '%env(CACHE_NAMESPACE)%' # Settings for HttpCache purge_server: '%env(HTTPCACHE_PURGE_SERVER)%' @@ -68,6 +72,8 @@ parameters: env(CACHE_DSN): localhost + env(CACHE_NAMESPACE): ez + env(HTTPCACHE_PURGE_SERVER): "http://localhost:80" env(HTTPCACHE_DEFAULT_TTL): 86400