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.


From the docs @ it states that phql queries are cached. If there is no caching enabled is that shared memory cache? IE the cache is shared between requests.

edited Nov '14

I haven't actually tried this yet but I've just gone through the code of the above class and this is how it should work:

// Instantiate the Query
$query = new Phalcon\Mvc\Model\Query("SELECT * FROM Cars", $this->getDI());

$query->cache(['key' => 'yourResultsetIdentifier', 'lifetime' => 1000, 'service' => 'myModelsCache' ]);

// Execute the query returning a result if any
$cars = $query->execute();

Near as I can tell these are the available options:

  • key = identifier for the result set

  • lifetime = lifetime of the cache, default 3600

  • service = name of the caching service in the DIC, default "modelsCache". It expects an object/class, it doesn't state what kind though from what I'm seeing in the functionality it should be a class that implements \Phalcon\Cache\BackendInterface.

Thanks for the response but that is not what I was asking about. There is no issue. I am just looking for clarification from the documentation of PHQL lifecycle. The documentation states: "PHQL statements are parsed once and cached in memory. Further executions of the same statement result in a slightly faster execution" I am just asking about more details about the caching. Is it shared memory or not. Meaning that caching would only happen per request.

I understand that if I implement caching on my own then yes it will live as long as I set it to live.


PHQL planning is currently cached per request. Regarding, resultsets returned by the execution of PHQL, they can be cached using any backends that implements \Phalcon\Cache\BackendInterface