zend-framework2zend-cache

What is the correct approach to the single sql query cache in ZF2?


I look through the documentation for Zend\Db, and I can not find any answers on how to cache individual queries (Rowset objects).

I know that Zend\Db in ZF2 is much more simplified compared to the ZF1... But still i do not want in my project use Doctrine etc.

And of course I know that my question is little bit too generic...


Solution

  • I think the following bloc-post describes exactly what you ask about: http://samsonasik.wordpress.com/2012/09/27/zend-framework-2-using-zendcache-and-hydratingresultset-to-save-database-resultset/

    In short:

    1. instantiate cache storage instance
    2. look in cache
    3. If not in cache
      1. load from db (retrieve instance of ResultSet)
      2. convert ResultSet into serializable data structure (like an array)
      3. write serializable data structure to cache
    4. if in cache you'll get the serializable data structure
    5. handle data (no longer an instance of ResultSet)