thinkPHP's F method can only be used to cache simple data types, and does not support validity periods and cached objects . The S() cache method supports validity period, also known as dynamic cache method. The usage examples are as follows:
Copy code The code is as follows:
// Use data identifier to cache $Data data
S('data',$Data) ; //The front is the cache mark, and the back is the cached data
Copy code The code is as follows:
// Cache $Data data 3600 seconds
S('data',$Data,3600);
Copy code The code is as follows:
//Delete cached data
S('data',NULL); //The first parameter is the cached identification name
Copy code The code is as follows:
$cache=S($cachename);//Set cache flag
// Determine whether there is a cache for this query
if(!$cache){ //$cache is the identifier of the cache (each query corresponds to a cache, that is, different queries have different caches)
$ cache=$video->where($map)->order($order)->limit($limit)->select();
foreach($cache as $key=>$value ){
$userlist=$user->where("id=".$value['user_id'])->find();
$cache[$key]["nickname"]= $userlist['nickname'];
}
S($cachename,$cache,3600); //Set cache survival time
}
S($cachename,NULL); // Delete cache
http://www.bkjia.com/PHPjc/802212.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/802212.htmlTechArticlethinkPHP’s F method can only be used to cache simple data types and does not support validity periods and cache objects. The S() cache method supports validity period, also known as dynamic cache method. The usage example is as follows: Copy...