Skip to content

Commit

Permalink
[YML] Add default cache prefix in order to share cache across cluster (
Browse files Browse the repository at this point in the history
…ezsystems#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.
  • Loading branch information
andrerom committed Aug 23, 2018
1 parent c3dc333 commit 7fc0616
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/config/cache_pool/cache.memcached.yml
Expand Up @@ -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%'
7 changes: 7 additions & 0 deletions app/config/cache_pool/cache.redis.yml
Expand Up @@ -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%'
6 changes: 6 additions & 0 deletions app/config/default_parameters.yml
Expand Up @@ -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)%'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7fc0616

Please sign in to comment.