Overview of ThinkPHP cache method S of

  • 2021-06-29 10:40:33
  • OfStack

The F method of thinkPHP can only be used to cache simple data types and does not support expiration and caching objects.The S () caching method supports expiration dates, also known as dynamic caching, as shown in the following example:

//  Use data Identity Cache $Data data 
S('data',$Data);  // Cached data follows cached data

//  cache $Data data 3600 second 
S('data',$Data,3600);


//  Delete Cached Data 
S('data',NULL);  // No. 1 Identification name of the cache for each parameter



$cache=S($cachename);// Set Cache Label 
// Determine if there is this query cache    
if(!$cache){  //$cache Cached in ( Each query corresponds to 1 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

More readers interested in thinkPHP-related content can view this site's topics: Introduction to ThinkPHP, Summary of thinkPHP Template Operation Skills, Summary of ThinkPHP Common Methods, Es23EN Template Introduction Basic Tutorial, and PHP Template Technology Summary.

I hope that the description in this paper will be helpful to everyone's PHP program design based on the ThinkPHP framework.


Related articles: