Memcached and PHP

There are plenty of resources out there on getting PHP and memcache to work together, and a basic installation and configuration should pose no problems. Making proper use of the caching technology, especially so that cached data remains 'clean' (ie, not out of date or 'dirty'), is quite a different matter.

Understand Dependencies

Any resource that you put into the cache must be locatable so that the cache item can be invalidated when you update that resource. It's no good putting a bunch of data into a slot if those data do not have a key in common.

Memcached Is Not Searchable

Because I cannot say "remove all items in the cache with a key containing 'member12345'", I need a way of looking up the relevant slot.

I have established two distinct methods of storing data so that they can be reliably disposed of:

  • Single cache slot for everything that depends on the resource
  • Versioning directory which can implicitely invalidate cache slots by making them inaccessible (as the key for those slots has an out-of-date version for its resource)


It's quiet in here...Add your comment