On Jun 24, 8:44 am, Markus <[email protected]> wrote:
> My apologies if this mail may appear slightly off-topic.
>
> Is there a php database abstraction layer which uses memcached for caching?

I experimented with this for a while, then I realised, caching really
has no place within the database abstraction layer itself, and
actually just makes things FAR more complicated in the long run.  Have
a look at Zend_Cache with the memcached backend.  The Class front-end
for it gave me all the inspiration I needed to add caching to my
domain model far more discreetly, while making it easy to warm or
fresh cache items by using a customised memcached backend which always
reports misses.

Having caching in the abstraction layer leads to a lot more caches
misses apart from anything else.  If a particular operation in your
application requires 3 separate database queries in order to complete,
and those 3 operations aren't used anywhere else, then having the
abstraction layer caching each one is a waste.  Apart from anything
else, if the first of the three misses the cache, the next 2 are
likely to as well, but the abstraction layer is not necessarily going
to know that, and so you'll get 3 cache misses and still get the 3
queries.  However, if you simply wrap the entire call using
Zend_Cache, then you get either one result from the cache, or the 3
queries get run.  The only code which even knows about any caching is
the code which provides the instance to the cache object instead of
the object it's wrapping.

To me, this makes far more sense, and in practice, using this approach
has really improved the cache hit ratio we get, and given us
significant reductions in database load.

Reply via email to