coen-hyde / Shanty-Mongo

Shanty Mongo is a mongodb library for the Zend Framework. Its intention is to make working with mongodb documents as natural and as simple as possible. In particular allowing embedded documents to also have custom document classes.
Other
200 stars 52 forks source link

Caching layer in queries #67

Closed quard8 closed 12 years ago

quard8 commented 12 years ago

I'm thinking about caching layer which should be simple and don't break current behaviour of constructing queryies.

Ideal solution is to add cache() function in query chain, like this:

$users = User::all()->cache($key, $time)->limit(5);

the problem is that function all() returns MongoCursor object, and we can't handle sort() and limit(), because cache data will be invalid.

Currently I can't imagine how to implement this. Maybe add some abstraction layer behind MongoCursor, or something different.

Any suggestions?

tholder commented 12 years ago

Adding a caching layer in to the core of Shanty isn't really a sensible way to go. It would be a lot of work to do it in a manageable abstracted way and distract from the core purpose of the library.

There are lots of caching options around but you might want to look at the Zend Framework caching options as a starting point.

See this for example:

http://www.joeyrivera.com/2009/caching-using-phpzend_cache-and-mysql/

gwagner commented 12 years ago

I have a Shanty-Mongo Cache adapter in my Fork if you want a quick caching layer.

quard8 commented 12 years ago

Actualy I need to cache mongodb requests and not mongodb as backend for cache :)

gwagner commented 12 years ago

I made a custom TwoLevels class (i can email it too you if you would like) that will cache the results of my complex queries to both mongo and memcache to speed things up, and if we dont find something in memcache, it will get re-primed out of the mongo cache, and since i am always doing a key based request, my queries are really really really fast.

quard8 commented 12 years ago

Oh, this can be useful for me, please send to quard8 at gmail dot com. Thanks!