Ticket #723 (new Feature Request)

Opened 4 months ago

Last modified 2 weeks ago

Cache should allow memcache multi_get for performance

Reported by: hans Owned by: - No owner -
Priority: major Milestone: 2.3
Component: Libraries:Cache Version: SVN HEAD
Keywords: memcache Cc: mark@…

Description

The get($id) method of the Cache library breaks when passed an array of keys. ($this->driver->get($id) returns an array, which errors out since if (substr($data, 0, 14) === '<{serialized}>') expects a string).

Memcache::get performance is enhanced when passed an array rather than multiple individual calls, as the requests can be made in parallel and often spread across multiple memcache servers.

Attachments

ticket-723.diff (1.7 kB) - added by dynom 2 weeks ago.
Patch to allow disabling pre-serializing, per driver. And disable it for the memcache driver
ticket-723_with_proposal.diff (3.4 kB) - added by dynom 2 weeks ago.
Same as previous patch, only now with the proposal.

Change History

Changed 4 months ago by hans

  • type changed from Bug to Feature Request

The get() and set() methods of the Cache library and its related drivers should be refactored so that serialization and unserialization takes place within the drivers when necessary. In the case of the memcache driver, serialization and unserialization would never be necessary since anything other than a string or int is automatically serialized and unserialized by the native Memcache methods. (This refactoring would also fix the issue described above with passing in an array.)

Changed 5 weeks ago by Shadowhand

  • milestone changed from 2.2 to 2.3

Changed 2 weeks ago by dynom

Patch to allow disabling pre-serializing, per driver. And disable it for the memcache driver

Changed 2 weeks ago by dynom

  • cc mark@… added

Geert and I discussed this during a Bughuntday meeting (The topic was Zend Framework, but Geert and I made it our own Kohana meeting ;-) ), the previously attached patch is partially the feature-request. It allows cache back ends to do their own serializing, however it does not fix the array parameter getting of data. Since this forces some active design changes.

e.g.: If $id is an array of two id's, like: $id = array('a/a','b/b');. How would the return value be like, if both are already arrays? The Id's are translated from / or \\ to = to keep valid key names, so returning a associative array might be inconsistent:

$cache->set('a/a', range(0,10));
$cache->set('b/b', range('a','z'));

var_dump( $cache->get(array('a/a','b/b')) );

// Return a-1, with the current translated id's
array(
 'a=a' => array(0,10),
 'b=b' => array('a','z')
)

// Return a-2, with the untranslated id's
array(
 'a/a' => array(0,10),
 'b/b' => array('a','z')
)

// Return n
array(
 0 => array(0,10),
 1 => array('a','z')
)

Return A-2, would be most favorable (for obvious reasons) and doable of the original id's will remain available when returning data. However it leads to a inconsistent return value when called with a single id.

Proposal to introduce a new method e.g.: getMultiple and possibly a counter part: setMultiple rather then changing the current set and get

Changed 2 weeks ago by dynom

Same as previous patch, only now with the proposal.

Changed 2 weeks ago by Geert

Memcache driver now takes care of seriliazing stuff itself, r3652.

Note: See TracTickets for help on using tickets.