The paginator of itself cannot be cached, and the source code can be directly modified to facilitate caching
/lib/cake/controller/component/paginatorcomponent.php to 196 rows and approximately 215 rows
/* Modify the code source code only for $results = $object->find ($type, Array_merge ($parameters, $extra)), */if (!isset ($options [' cache_ Config]) {$results = $object->find ($type, Array_merge ($parameters, $extra));} else{$cache _key = ' paginator_cache_ '. $object->name. ' _page_ '. $page; $results = Cache::remember ($cache _key, function () use ($object, $type, $parameters, $extra) {return $ob Ject->find ($type, Array_merge ($parameters, $extra));}, $options [' Cache_config ']);} Start to modify the above code is only convenient location/* Modify the Code source code is only $results = $object->find ($type, Array_merge ($parameters, $extra)); */if (!isset ($ options[' Cache_config ')){$count = $object->find (' Count ', Array_merge ($parameters, $extra));} else{$cache _key = ' paginator_cache_ '. $object->name. ' _count '; $count = Cache::remember ($cache _key, function () use ($object, $type, $parameters, $extra) {return $ Object->find (' Count ', Array_merge ($parameters, $extra));}, $options [' Cache_config ']);}
How to use:
First modify the core.php
Probability represents a probability to view the source code can be known as time ()% $probability ==0 when called CACHE::GC () cache::config (' Common_paginator_cache_redis ', Array( ' engine ' = ' Redis ', ' duration ' = ' +15 minutes ', ' probability ' = ') ';
Controller modified in:
Use the method//Add the following code to set the cache config so that no other code needs to change $this->paginate = array( ' limit ' = = ', ' cache_config ' = ' Common_paginator_cache_redis '//new matching configuration in core.php);