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