Welcome Guest, Not a member yet? Register   Sign In
How to reuse a query
#1

(This post was last modified: 11-08-2021, 02:01 AM by JerryCode.)

The user table has 20 rows.
PHP Code:
//1.create a query
$result $this->news_model->where('id>',10);//10 results
//2.get the count
$count = $result->countAllResults(); //10 results
//3.return the result(There should be only 10 results)
$all = $result->findAll(); //20 results 
How to reuse the query ?

My solution is to use caching

cache()->save('result',$result); // save cache

$count = cache(‘result’)->countAllResults(); //10 results, use cache

$all = $result->findAll(); //10 results , if use pagination, can not use cache data here

cache()->delete('result'); //delete cache
Reply




Theme © iAndrew 2016 - Forum software by © MyBB