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