public function get_cache($expiration = false) { $result = null; //hash the current query $md5_hash = md5($this->get_query()); try { //see if cache exists $result = \Cache::get($md5_hash); } catch (\CacheNotFoundException $e) { //no cache found, execute query and set cache $result = $this->get(); \Cache::set($md5_hash, $result, $expiration); } return $result; }
$comments= Model_Comment::find() ->related('user') ->limit(30) ->get_cache(60);
$comments= Model_Comment::find() ->related('user') ->limit(30) ->cache(60) ->get()Also, if you want this: make the feature request on Github or (better) write it up and pull-request. We don't accept either feature reqeusts or bugs on the forums, that's what the issue tracker on Github is for. @hueman
your explanation seems to be prudentlyJelmer Schreuder wrote on Wednesday 24th of August 2011:@hueman
Both are easily explained: this needs to load the Cache library and needs filesystem access, both of which will add a little to memory and execution. But the point of caching isn't to speed up single-user usage, it is to make sure that your app stays scalable and fast with many users accessing at the same time. Databases are a lot more scaleable in ammount of data it can deal with, but mysql isn't very scaleable when it comes to simultanious access of many users. Which is where caching comes in: filesystem access (or even better: Memcached or Redis) is a lot faster to access and more scaleable in simultanious access.
Also when dealing with big amounts of data this might be faster to load like this than to have hydration do its work after a database load.
Mainly the idea is that it may increase a bit but remain almost constant when traffic increases. While without caching the mySQL response time might start slowing down immensely. I don't get how memory usage & total time could increase 30% unless maybe when you're testing on a clean installation without anything else going on, caching is not that heavy and neither are the files it creates - especially compared to any real work going on.but when i send several requests (eg: 1000 request) to the page uses this caching solution, memory usage and total time increases too
this solution increases memory usage and total time for me, at least 30% whether webserver responses one request or more
what is your idea?
Andrew Black wrote on Wednesday 7th of September 2011:Just a thought: MySQL can use query cache which would make ORM caching redundant. I am not sure this is the case here but it might explain longer loading times.
It looks like you're new here. If you want to get involved, click one of these buttons!