views:

152

answers:

1

Hi!

Im trying to find a good way to handle memcache keys for storing, retrieving and updating data to/from the cache layer in a more civilized way.

Found this pattern, which looks great, but how do I turn it into a functional part of a PHP application?

The Identity Map pattern: http://martinfowler.com/eaaCatalog/identityMap.html

Thanks!

Update: I have been told about the modified memcache (memcache-tag) that apparently does do a lot of this, but I can't install linux software on my windows development box...

+4  A: 

Well, memcache use IS an identity map pattern. You check your cache, then you hit your database (or whatever else you're using). You can go about finding information about the source by storing objects instead of just values, but you'll take a performance hit for that.

You effectively cannot ask the cache what it contains as a list. To mass invalidate, you'll have to keep a list of what you put in and iterate it, or you'll have to iterate every possible key that could fit the pattern of concern. The resource you point out, memcache-tag can simplify this, but it doesn't appear to be maintained inline with the memcache project.

So your options now are iterative deletes, or totally flushing everything that is cached. Thus, I propose a design consideration is the question that you should be asking. In order to get a useful answer for you, I query thus: why do you want to do this?

Autocracy
Thanks Autocrazy. The reason why we would like to mass-invalidate stuff, is basically to be able to create relationships between the stored keys and force invalidation on all related keys on change in the mySQL database.
Industrial