ThinkPHP cache method s () Overview

Source: Internet
Author: User
The F method of thinkPHP can only be used to cache simple data types. The validity period is not supported. The S () cache method supports the validity period, also known as the dynamic cache method. This article mainly introduces the ThinkPHP cache method s ().

The F method of thinkPHP can only be used to cache simple data types. The validity period is not supported. The S () cache method supports the validity period, also known as the dynamic cache method. This article mainly introduces the ThinkPHP cache method s ().

The F method of thinkPHP can only be used to cache simple data types, and does not support validity periods and cache objects. The S () cache method supports the validity period, also known as the dynamic cache method. The 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 identifier, followed by the cached Data


The Code is as follows:

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



The Code is as follows:

// Delete cache data
S ('data', NULL); // The cached identifier when the first parameter is set.



The Code is as follows:

$ Cache = S ($ cachename); // you can specify the cache ID.
// Determine whether the query cache exists
If (! $ Cache) {// $ cache indicates 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); // sets the cache survival time.
}
S ($ cachename, NULL); // deletes the cache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.