Object cached methods (fs and memcache backends) patch

39 views
Skip to first unread message

sergio...@gmail.com

unread,
Nov 28, 2009, 9:35:27 PM11/28/09
to SilverStripe Development
Last year Ive made a patch to another CMS to transparently (through
__call mangling) cache method calls from model and controller objects,
instead of calling obj->method() you call obj->methodCached() and
'tada!', you get cached calls with filesystem or memcached backends.

In the process of building 2 sites with Silverstripe my mind started a
big "if..", so I tried to bring the same ideia to Silverstripe.

Trying to bring some brainstorm to it Im publishing an initial semi-
working (more on that later) patch (lot of syslog()-ing all over the
place) against trunk, already with 2 backends, filesystem-based and
memcached-based.

semi-working? Actually calling cached methods directly from templates
is broken, currently dont know why yet.

Included too is a little module with a test page of the patch.

Future direction of development:
a) implement a __call_static(), too, to be able to use cached calls of
Data_Object::get*.
b) investigate why currently I cant use cached calls directly from
templates.

Patch agains trunk and test module you can get at http://sergio.bruder.com.br/silverstripe/

Sergio Bruder
http://sergio.bruder.com.br/

sergio...@gmail.com

unread,
Nov 28, 2009, 11:18:23 PM11/28/09
to SilverStripe Development
Replying to myself, 2 'one more things', micro-instructions to use and
a comment about the memcache client.

in your _config.php:
// cachedobjects backend configuration
// CachedObjects::set_backend('memcached',array('servers' => array
('localhost:11211'), 'compress_threshold' => 20000, 'min_savings' =>
0.2));
CachedObjects::set_backend('fs',array());
CachedObjects::set_default_methodcache_time(10);

To use it:
call $object->yourmethodCached() instead of $object->yourmethod().

The memcache client:

The code first tries to use the PECL one, binary. If not present, we
fallback to the php-only one included in the patch.


On Nov 29, 12:35 am, "ser...@bruder.com.br" <sergio.bru...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages