CakePHP 2.5 uses Redis cache paginator data

Source: Internet
Author: User

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.