Persistence caching with memcache in eZ Publish 5.x and eZ Platform
In eZ Publish 5.x and eZ Platform, the concept of "view cache" has changed. The "module result" part of it (which was basically page-level caching if we didn't count the pagelayout) has been offloaded to HTTP caching, most often implemented with Varnish. In addition, Cache blocks no longer exist and have been replaced by ESI (Edge Side Includes) blocks.
The persistence caching element -- that is, caching of your actual content from the database -- of the "view cache" still exists, handled by default on the file system through the Stash bundle. Stash also supports memcache (which, as its name suggests, uses memory, and has a much better performance). We use memcache(d) for all of our production sites.
How to use memcache in eZ Publish
Installing memcache or memcached is straightforward. The reference documentation is good, and you can often use the default settings. As an example, on Ubuntu 14 this command is likely all you need:
sudo apt-get install php5-memcached memcached
On the eZ Publish side, this is the default configuration, which you usually end up placing in environment-specific configurations in ezpublish/config/ezpublish_<env>.yml such as ezpublish_prod.yml:
stash: caches: default: drivers: # When using multiple webservers, you must use Memcache or Redis - Memcache inMemory: true registerDoctrineAdapter: false Memcache: prefix_key: yoursite_ retry_timeout: 1 servers: - server: 127.0.0.1 port: 11211
You can add multiple servers to have a memcache pool. If you have a cluster setup, you can simply install memcache on each front-end server. See the eZ documentation for more information. If each front-end server has the same configuration files, use internal network IPs in the configuration instead of using 127.0.0.1 (since every server's pointer for 127.0.0.1 is to itself and thus technically different!)
Also, make sure there is no Stash configuration remaining in the default ezpublish/config/ezpublish.yml file. This could trip you up by overriding your environment-specific settings!
Bonus note: If you have front-end sessions in a cluster, you should also use memcache to store sessions. Use a second memcache pool, however, to minimize the risk that sessions get bumped out of memory by non-session data from eZ's persistence caching.
Is memcache working?
You'll know pretty quickly if persistence caching is not working because you'll make content changes that won't be reflected properly on your website. Here are some tips to get started and make sure the persistence caching is working fine:
- Check that you can connect to the default memcache port on the server: telnet localhost 11211
- Then, run the stats command, which will show you basic information such as cache hits and misses. When you reload a page on your website, see that these numbers change.
- Empty your ezpublish/cache folder and then check that it is no longer growing with each page load beyond a few megabytes total (or more, depending on the size of your site): du -hs ezpublish/cache. There should still be files there, because some system components still use file caching such as for compiled template caching.
In non-prod environments you can check your compiled YML settings by running this command:
php ezpublish/console debug:config ezpublish
... with the optional parameter --env=<environment> such as --env=stage
(We're still on the hunt for a production "settings check" feature similar to how we can use Setup > Ini settings for legacy settings in the Administration Interface.)
Commentsblog comments powered by Disqus
Hi, we're Mugo Web - Nice to meet you!
We're a group of web experts who solve complex web problems.Learn more about us »
- Business solutions (61)
- Case study (24)
- eZ Publish add-ons (21)
- eZ Publish community (11)
- eZ Publish development tips (64)
- Front-end development (1)
- Productivity tools (12)
- Site performance (10)
- User experience (29)
- Web accessibility (14)
- Web solutions (60)
- Work at Mugo (10)
Yes - we can do that.
Many years of experience with complex websites allows us to offer total solutions.Learn more about what we can do »
We love our clients (and they love us too)
We've solved problems across North America and around the world.Learn more about what we've done »
We tweet too
Follow us on Twitter for the latest Mugo happenings