Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

What is the most simple way to cache model searches in memory for a single request (with no backend)?

Say that I want to do Hats::find() and to have those results be cached just in memory for that request. At this point I'm not interested in configuring a backend, even a file one, since I'm currently trying to accomplish a few other things. So I'm just looking to get off of the ground for now to use what in 2-3 months will be a much more involved caching system.

edited Feb '15

Using the service modelsCache with \Phalcon\Cache\Backend\Memory.

# Register the service
$di->set('modelsCache', function () {
    return new \Phalcon\Cache\Backend\Memory(new \Phalcon\Cache\Frontend\Data);

And when querying pass the cache key in parameters

Hats::find(['cache' => ['key' => 'all-hats']]);

edited Feb '15

Thanks, but please fix the quotes.

[edit] When people see all of those crazy characters they are going to think that is what Zephir looks like. ;)