We have discussed the PHP caching technology in depth before, and mainly talked about data caching. Data cache mainly refers to the database query cache. when accessing the page every time, the corresponding cache data will be checked first... we have discussed the PHP caching technology in depth before, and mainly talked about data caching. Data cache mainly refers to the database query cache. each time you access the page, it first checks whether the cache data exists. if it does not exist, it connects to the database to obtain the data, close the query...
We have discussed the PHP caching technology in depth before, and mainly talked about data caching. Data cache mainly refers to the database query cache. each time you access the page, it first checks whether the cache data exists. if it does not exist, it connects to the database to obtain the data, serialize the query results and save them to the file. later, the same query results will be obtained directly from the cache table or file.
The most widely used example is the Discuz search function. The result ID is cached in a table and the table is searched in the cache next time when the same keywords are searched.
For example, when multiple tables are joined, an array generated in the appendix is saved to a field in the master table. if necessary, the array is decomposed, the advantage is read-only tables. The disadvantage is that two data synchronization steps are many more steps, and the database is always the bottleneck. Changing the disk speed is the key point.
Page cache
Each time you access the page, the system first checks whether the corresponding cached page file exists. if it does not exist, it connects to the database to obtain data, displays the page, and generates cache page files at the same time, in this way, the page file will play a role in the next visit. (The template engine and some common cache classes on the Internet usually have this function)
Time-triggered cache
Check whether the file exists and the timestamp is earlier than the set expiration time. if the modified timestamp of the file is greater than the current timestamp minus the expiration timestamp, use the cache; otherwise, update the cache.
Content trigger cache
When data is inserted or updated, the cache is forcibly updated.
Static cache
The static cache mentioned here refers to static, which directly generates HTML, xml, and other text files. it is re-generated once when there is an update. this is suitable for pages that do not change much.
Memory cache
Memcached is a high-performance, distributed memory object cache system that reduces database loads in Dynamic Applications and improves access speeds.
$ Memcache = new Memcache;
$ Memcache-> connect ('localhost', 11211) or die ("cocould not connect ");
$ Version = $ memcache-> getVersion ();
Echo "Server's version:". $ version. "\ n ";
$ Tmp_object = new stdClass;
$ Tmp_object-> str_attr = 'test ';
$ Tmp_object-> int_attr = 123;
$ Memcache-> set ('key', $ tmp_object, false, 10) or die ("Failed to save data at the server ");
Echo "Store data in the cache (data will expire in 10 seconds) \ n ";
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