Home > Backend Development > PHP Tutorial > Overview of ThinkPHP cache method S()_PHP tutorial

Overview of ThinkPHP cache method S()_PHP tutorial

WBOY
Release: 2016-07-13 10:28:14
Original
741 people have browsed it

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

www.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...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template