使用 CakePHP 进行缓存和分页 3.x

Cache and pagination with CakePHP 3.x

Here 是如何使用 CakePHP 缓存分页结果 2.x.

我还没有尝试过,但我相信同样的方法对 CakePHP 有效 3.x。

但是,由于 CakePHP 3.x 引入了几个使用缓存的新特性(例如,find() 方法采用 cache 选项),我想知道是否有更快的方法。

我看过书和 API,但没有提到这方面的任何特殊内容。

一件事:here解释说

By default the paginate() method will use the default model for a controller. You can also pass the resulting query of a find method:

也许是这个?我使用带有 cache 选项的 find() 方法,然后将结果传递给 paginate()?.

谢谢。

我不建议缓存查询,特别是分页结果。但是你的想法在理论上是正确的:

$aKeyThatEncodesQueryStringAndConditions = ...;
$this->paginate($this->Users->find()->cache($aKeyThatEncodesQueryStringAndConditions));