I’m using nginx, memcached and APC for all my sites. What I host is a wordpress site, a vBulletin forum and some other sites.
I’ve set up nginx and memcached so that nginx first checks the memcached server to see if it has an entry for the full page, if it doesnt pass the request along to PHP and cache the full page – then display it to the user, see link for configuration: http://pastebin.com/ZFSrA9e5
Currently the vBulletin forum is using the “$config[‘Datastore’][‘class’] = ‘vB_Datastore_Memcached’;” and the WP blog is using the Memcached Object Cache (http://wordpress.org/extend/plugins/memcached/)
I am only caching WP as the full page in memcached (as explained above) at the moment to see if I run into any issues – so far so good.
What I want to achieve is good loading times and low load. The issues I’ve ran into/questions I have ran into are these:
-
How do I know that for example a user logs in for the first time, memcached caches the request for the first user. Then the next user comes and memcached serves the cached page for the first user – does anything take this into account/prevent this?
-
How/when will memcached/nginx flush the full-site cache in order to update the cache?
-
Am I recommended to run both APC and memcached? As far as I’m aware; memcached caches small values and apc caches the compiled PHP code, correct?
Would be awesome if someone could enlighten me on these questions.
1) Your cache response solely depends of this:
So each cached-entry depends only of URI and user auth information does not make sense. Second request will be same as first one because it will have same memcache keys. If you want to store separate cache-keys for each logged user you’ll need to set more distinct key, something like this:
2) This depends of WP-plugin. Nginx never flushes the cache, to make force-flush you’ll need to restart memcache.
3) Yes, both of them do different things, APC caches compiled PHP code, so it dont have to compile each time with each request (it only recompiles with server restart or when php file is changed). Memcache stores some portions of page or the whole page (your scenario) in memory and when KEY provided by nginx found in memcache, PHP is not even involved – whole page serves directly from memcahced memory.
hope this helps)