Memcached getDelayed alternative implementation

Posted by iBobo on Stack Overflow See other posts from Stack Overflow or by iBobo
Published on 2010-06-14T21:25:18Z Indexed on 2010/06/15 21:42 UTC
Read the original article Hit count: 148

Filed under:
|
|

I would like to use getDelayed on the PHP Memcached extension but I think it's not implemented in the right way.

Right now you ask for some keys and then retrieve all of them with fetch() and fetchAll(). But imagine a scenario where I need to retrieve 15 keys used in different parts of the page which I don't know in advance, but I can ask the various objects to give me the list. What I want is give the Memcached instance this list (each component would give its part) then later when I need them retrieve from the instance, but not all of them at once: each component would take the one it needs.

Basically if I were to implement this I would prohibit using getDelayed alone and implement a bookGet($keys) method where you would add the keys to book (which actually calls getDelayed), and redefine get to handle these three cases:

  1. key is booked and retrieved -> return the value;
  2. key is booked but not retrieved -> go and force the fetch of the booked keys and return the correct value;
  3. key not booked -> do a normal lookup.

I want to know if this makes sense, your thoughts on the subject and if someone already implemented this or maybe PECL Memcached already works this way and actually the documentation doesn't explain it correctly.

© Stack Overflow or respective owner

Related posts about php

Related posts about caching