Message-ID: <1088933904.3496.1485853410714.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3495_1025403322.1485853410713" ------=_Part_3495_1025403322.1485853410713 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Persistence cache configuration

Persistence cache configuration


=20 =20

Introduction

Tech Note

Current implementation uses a caching library called Stash (= , via Stash-bundle). Stash supports the following cache backends= : FileSyste= mMemcache, APC, Sqlite, Redis and BlackHole.

Use of Memcached (or experimentally using Redis) is a requirement fo= r use in Clustering setup, for overview of clustering feature see Clustering

If eZ Publish Pla= tform changes to another cache system, configuration will change in the fut= ure, changes to configuration in StashBundle is listed here:

Configuration change in 5.4/2014.07

StashBundle version bundled with 5.4/2014.07 and higher refers to cache = backends as "drivers" where it was previously referred to as "= handlers" in yml configuration

Cache service

The cache system is exposed as a "cache" service, and can be reused by a= ny other service as described on the Persistence cache page.

Configuration

During Setup wizard and manually using ezpublish:configure&= nbsp;console command a default configuration is generated currently using FileSystem, using %kernel.cache_dir%/stash to = store cache files.

The configuration is placed in ezpublish/config/ezpublish.yml, and looks= like:

Default ezpublish.yml
=20
stash:
    caches:
        default:
            # For eZ Publish Platform versions prior to 5.4/2014.07, use "h=
andlers" instead of "drivers"!
            drivers:
                - FileSystem
            inMemory: false
            registerDoctrineAdapter: false
=20

The default settings used during setup wizard as found in ezpublis= h/config/ezpublish_setup.yml:

ezpublish_setup.yml
=20
stash:
    caches:
        default:
            # For eZ Publish Platform versions prior to 5.4/2014.07, use "h=
andlers" instead of "drivers"!
            drivers:
                - BlackHole
            inMemory: true
            registerDoctrineAdapter: false
=20

This setting works across all installs and just caches objects= within the same request thanks to the inMemory: true setting.=

If you want to change to another cache backend, see in Stash backend= configuration below for what kind of settings you have available.

Note for "inMemory" cache with long running scripts

Use of inMemory caching with BlackHole or any other cache b= ackend should not be used for long running scripts as it will over time ret= urn stale data, inMemory cache is not shared across requests/processes, so = invalidation does not happen!

Multi reposit= ory setup

New in 5.2 is the possibility to select a specific Stash cache pool on a= siteaccess or sitegroup level, the following example shows use in a sitegr= oup:

ezpublish.yml site group setting
=20
        ezdemo_group:
            cache_pool_name: "default"
            database:
                ...

=20

The "default" here refers to the name of the cache pool as specified in = the stash configuration block shown above, if your install ha= s several repositories (databases), then make sure every group of sites usi= ng different repositories also uses a different cache pool to avoid un= wanted effects.
NB: We plan to make this more native in the future, so t= his setting will someday not be needed.

Sta= sh cache backend configuration

General settings

To check which cache settings are available for your installation, run t= he following command in your terminal :

=20
php ezpublish/console config:dump-reference stash
=20

FileSystem=

This cache backend is using local filesystem, by default the Symfony cac= he folder, as this is per server, it does not support multi se= rver (cluster) setups!

We strongly discourage you from storing cache files on NFS= , as it defeats the purpose of the cache: speed

Availab= le settings

path
The path where the cache is placed, default is <= code>%kernel.cache_dir%/stash, effectively ezpublish/cache/<= ;env>/stash
dirSplit
Number of times the cache key shou= ld be split up to avoid having to many files in each folder, default is 2.<= /td>
filePermissions
The permissions of the cache file,= default is 0660.
dirPermissions
The permission of the cache file d= irectories (see dirSplit), default is 0770.
memKeyLimit

Limit on how many key to path e= ntries are kept in memory during execution at a time to avoid having to rec= alculate the path on key lookups, default 200.

keyHashFunction
Algorithm used for creating paths,= default md5. Use crc32 on Windows to avoid path length issues.=

Issues with Microsoft Windows

If you are using a Windows OS, you may encounter an issue regarding long paths for cache directory name. The paths are long becaus= e Stash uses md5 to generate unique key that are sanitized really quickly.<= /p>

Solution is to change the hash algorithm used by Stash.=

Specifying key hash function
=20
stash:
    caches:
        default:
            # For eZ Publish Platform versions prior to 5.4/2014.07, use "h=
andlers" instead of "drivers"!
            drivers:
                - FileSystem
            inMemory: true
            registerDoctrineAdapter: false
            FileSystem:
                keyHashFunction: 'crc32'
=20

This configuration is only recommended for Windows users.

Note: You can also define the path where you wan= t the cache files to be generated to be able to get even shorter system pat= h for cache files.

 

FileSystem cache backend troubleshooting

By default, Stash Filesystem cache backend stores cache to a sub-folder = named after the environment (i.e. ezpublish/cache/devezpublish/cache/prod). This can lead to the following issue : if= different environments are used for operations, persistence cache (manipul= ating content, mostly) will be affected and cache can become inconsistent.<= /p>

To prevent this, there are 2 solutions :

  1. Manual

    Always use the same e= nvironment, for web, command line, cronjobs...

  2. Share stash cache across Symfony environments (prod / = dev)

Either by using another Stash cache backend, or by setting Stash to use = a shared cache folder that does not depend on the environment. 
In = ezpublish.yml:

=20
stash:
    caches:
        default:
            FileSystem:
                path: "%kernel.root_dir%/cache/common"
=20

This will store stash cache to ezpublish/cache/common.=

APC

This cache backend is using shard memory using APC's user cache feature,= as this is per server, it does not support multi server (cluster) setups.

Limitation

As APC user cache is not shared between processes, it is not possible to= clear the user cache from CLI, even if you set apc.enable_cli to On. Hence publishing content = from a command line script won't let you properly clear SPI Persistence cac= he.

Please also note that the default value for apc.shm_size is 128MB. However, 256MB is recommended for APC to work properly. For mo= re details please refer to the APC configuration manual.

 

Available settings

ttl The time to live of the cache in seconds, defaul= t set to 500 (8.3 minutes)
namespace A namespace to prefix cache keys w= ith to avoid key conflicts with other eZ Publish sites on same eZ Publish i= nstallation, default is null.

Memcache

This cache backend is using Memcached, a distributed caching solution, this is the only supported cache solution for multi server (cluster) setups!

Note

Stash supports both the php-memcache and php-memcached exte= nsions. However only php-memcache is officially tested on = Redhat/Centos while php-memcached is on Debian and Ubuntu. If you ha= ve both extensions installed, Stash will automatically choose php-memcache<= u>d.

servers

Array of Memcached servers, wit= h host/IP, port and weight

server: Host= or IP of your Memcached server
port: Port= where Memcached is listening to (defaults to 11211)
weigh= t: Weight of the server, when using several Memcached serve= rs

prefix_key<= /code> A namespace to prefix cache = keys with to avoid key conflicts with other eZ Publish sites on same eZ Pub= lish installation (default is an empty string).
Must be th= e same on all server with the same installation. See Memcached pr= efix_key option. =E2=9C=B2=
compression= default true. See Memcached compression op= tion. =E2=9C=B2
libketama_compatible= default false. <= a href=3D"http://www.php.net/manual/en/memcached.constants.php#memcached.co= nstants.opt-libketama-compatible" class=3D"external-link" rel=3D"nofollow">= See Memcached libketama_compatible option =E2=9C=B2
buffer_writes default false. <= a href=3D"http://www.php.net/manual/en/memcached.constants.php#memcached.co= nstants.opt-buffer-writes" class=3D"external-link" rel=3D"nofollow">See Mem= cached buffer_writes option =E2=9C=B2
binary_protocol default false. <= a href=3D"http://www.php.net/manual/en/memcached.constants.php#memcached.co= nstants.opt-binary-protocol" class=3D"external-link" rel=3D"nofollow">See M= emcached binary_protocol option =E2=9C=B2
no_block default false. <= a href=3D"http://www.php.net/manual/en/memcached.constants.php#memcached.co= nstants.opt-no-block" class=3D"external-link" rel=3D"nofollow">See Memcache= d no_block option =E2= =9C=B2
tcp_nodelay= default false. <= a href=3D"http://www.php.net/manual/en/memcached.constants.php#memcached.co= nstants.opt-tcp-nodelay" class=3D"external-link" rel=3D"nofollow">See Memca= ched tcp_nodelay option =E2=9C=B2
connection_timeout default 1000. See= Memcached connection_timeout option =E2=9C=B2
retry_timeout default 0. See Mem= cached retry_timeout option =E2=9C=B2
send_timeout default 0. See Memcache= d send_timeout option =E2=9C=B2
recv_timeout

default 0. See Memca= ched recv_timeout option =E2=9C=B2

poll_timeout default 1000. See Memca= ched poll_timeout option =E2=9C=B2
cache_lookups default false. <= a href=3D"http://www.php.net/manual/en/memcached.constants.php#memcached.co= nstants.opt-cache-lookups" class=3D"external-link" rel=3D"nofollow">See Mem= cached cache_lookups option =E2=9C=B2
server_failure_limit= default 0. See = PHP Memcached documentation socket_send_size
See Memcached socket_send_size option= . =E2=9C=B2 =E2=9C=B8
socket_recv_size See Memcached socket_recv_size option= . =E2=9C=B2 =E2=9C=B8
serializer See Memcached serializer option. =E2=9C=B2 =E2=9C=B8
hash= See Memcached hash option. =E2=9C=B2 =E2=9C=B8
distribution<= /strong>

Specifies the method of distrib= uting item keys to the servers. See Memcached distribution option. =E2=9C=B2 =E2=9C=B8

 

=E2=9C=B2 All settings but servers are only available with memcached php extension,= for more information on these settings and which version of php-memcached they are available in, see: http://php.net/Memcached
=E2=9C=B8
 If you are on eZ Publish 5.1, make sure= to update Stash and StashBundle to get access to these settings.

 

When using Memcache cache backend, it's recommended to also use = inMemory cache (see example below).
This will hel= p reducing network traffic between your webserver and your Memcached server= , unless you have very long running cli processes which then might end up a= cting on stale data.

Example with M= emcache

=20
stash:
    caches:
        default:
            # For eZ Publish Platform versions prior to 5.4/2014.07, use "h=
andlers" instead of "drivers"!
            drivers: [ Memcache ]
            inMemory: true
            registerDoctrineAdapter: false
            Memcache:
                prefix_key: ezdemo_
                retry_timeout: 1
                servers:
                    -
                        server: 127.0.0.1
                        port: 11211
=20

Connection errors issue

If memcached does display connection errors when using the default (asci= i) protocol, switching to binary protocol (in the stash configuration and m= emcached daemon) should resolve the issue.

------=_Part_3495_1025403322.1485853410713--