Thinkphp caching Method S () Overview _php instance

Source: Internet
Author: User

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.

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.