Issue
About the get()
method, I read here:
Like find() get has caching integrated. You can use the cache option when calling get() to perform read-through caching
But later, in the section dedicated to the find()
method (here), the cache is not mentioned, there are no examples for the cache and the cache
option is not mentioned among the supported options.
So I would like to know: can I use the cache
option with the find()
method? If so, how?
Thanks.
Thanks to ndm. So:
$query = $this->Pages->find('all');
$query->cache('all_pages');
$this->set('pages', $query->all());
Or (more simple):
$query = $this->Pages->find('all')->cache('all_pages');
$this->set('pages', $query->all());
Solution
The query builder doesn't suport caching via options, it has a separate method that is to be used, Query::cache()
, which you'd use like
$query = $table->find();
$query->cache('cache_key');
$query->cache('cache_key', 'configName');
$query->cache(function($query) {
return md5(
serialize($query->clause('select')) .
serialize($query->clause('where'))
);
});
// ...
See
get()
supports caching via an option as that's the only way to configure the internal find call, since it's being executed immediately so that get()
can return throw possible errors and return an entity.
Answered By - ndm
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.