Memcached getDelayed alternative implementation
- by iBobo
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:
key is booked and retrieved - return the value;
key is booked but not retrieved - go and force the fetch of the booked keys and return the correct value;
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.