ThinkPHP cache method s () Overview

Source: Internet
Author: User

ThinkPHPMethod F 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:

Copy codeThe 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
Copy codeThe Code is as follows: // cache $ Data for 3600 seconds
S ('data', $ data, 3600 );

Copy codeThe Code is as follows: // Delete cache data
S ('data', NULL); // The cached identifier when the first parameter is set.



Copy codeThe Code is as follows: $ cache = S ($ cachename); // sets the cache identifier
// 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.