Static cache technology, static Cache

Source: Internet
Author: User

Static cache technology, static Cache


Essence: Saving webpage source code
Disadvantages: If the cache time is too long, the data will be updated in a timely manner; it cannot be used to update data in real time;

1. Use the smart template to call the display page
2. Define the cache storage directory;
Defines the cache time. After the cache time expires, the cache file is regenerated;
3. Determine whether the cached file exists and the last modification time + 10 s is later than the current time
Yes: Reference cached files

Does not exist: Generate cache file => (update cache: Regenerate cache file and reference it)
Enable the memory buffer; ob_start ();
Put the webpage code;
Get the content in the memory; $ str = ob_get_contents ();
Put the obtained content in the file in the cache directory; file_put_contents (cache file directory, content );
Disable the memory cache;


Pagination cache generation: cache is generated for each pagination page.
Define $ p = 0;
If get ["page"] is not blank, $ p is received, and the generated cache path file name is.../huanchunw.p;.html

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.