The thinkphp F method can be used only for caching simple data types, not for expiration and caching of objects . The S () caching method supports the validity period, also known as the dynamic caching method, using the following example:
Copy Code code as follows:
To cache $data data using the data identity
S (' data ', $Data); The front is the cache label, followed by the cached data
Copy Code code as follows:
Cache $data data for 3,600 seconds
S (' Data ', $Data, 3600);
Copy Code code as follows:
Deleting cached data
S (' data ', NULL); The identity name of the cache when the first parameter
Copy Code code as follows:
$cache =s ($cachename);//Set Cache mark
Determine if there is this query cache
if (! $cache) {//$cache is the cached indicator (each query corresponds to a cache that has different caches for different queries)
$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); To set the cache lifetime
}
S ($cachename, NULL); Delete Cache
More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "Smarty Template Introductory Course" and "PHP template technology Summary."
I hope this article will help you with the PHP program design based on thinkphp framework.