Home  >  Article  >  Backend Development  >  ThinkPHP caching method S overview

ThinkPHP caching method S overview

WBOY
WBOYOriginal
2016-08-08 09:23:421048browse

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 example is as follows:

. The code is as follows:

// Use the data identifier to cache $Data data
S('data',$Data); //The front is the cache mark, and the back is the cached data


. The code is as follows:

//Cache $Data data for 3600 seconds
S('data',$Data,3600);


. The code is as follows:

//Delete cached data
S('data',NULL); //The first parameter is the cached identification name


. The code is as follows:

$cache=S($cachename);//Set the cache label
// Determine whether there is a cache for this query
if(!$cache){ //$cache is the cache label (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 lifetime
}
S($cachename,NULL); //Delete cache

The above has introduced an overview of ThinkPHP caching method S, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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