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 ?



64.2k

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: http://dev.mysql.com/doc/refman/5.1/en/information-functions.html#function%5found-rows . So you're not doing the full, expensive query both times, and caching wouldn't have any affect.