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