: This article mainly introduces the ThinkPHP cache method S. If you are interested in the PHP Tutorial, refer to it. 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
The above introduces ThinkPHP cache method S overview, including the content, hope to be helpful to friends interested in PHP tutorials.