We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

how to cache query when using paginator

        $builder = $this->modelsManager->createBuilder();
        $builder->from('Koogua\Model\Entity\Thread');

        $paginator = new QueryBuilderPaginator([
            'builder' => $builder,
            'limit' => $limit,
            'page' => $page,
        ]);

        $page = $paginator->getPaginate();

two queries will be executed, one for total count , one for items.

is there some ways to cache the queries ?



85.5k

usually i use something like


'cache' => [
    'key' => 'my-results-page-'.$page
]

While 2 queries are being executed, I don't believe they're the same query. The query to get the items stores the total rows in SQL_CALC_ROWS, and the second query just retrieves that: https://dev.mysql.com/doc/refman/5.1/en/information-functions.html#function_found-rows . So you're not doing the full, expensive query both times, and caching wouldn't have any affect.