What are the common caching techniques in PHP
This article mainly shows you "what are the common caching technologies in PHP". The content is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what are the common caching technologies in PHP?"
The details are as follows:
In the process of development, JBLOG has done a lot of work on performance optimization. In order to minimize unnecessary database queries, I cached and statically processed some data.
How caching works: store some frequently used but rarely changed data in an array or other form in a separate PHP file and include it when needed.
The advantage of cache: it can greatly reduce the query times of the database, reduce the pressure on the database, and improve the execution efficiency of the program.
The data cached by JBLOG are: system settings, blog classification, sidebar latest logs, latest comments, blog statistics, log archives, links, tags and so on. By caching this data, the number of queries to a page database is reduced from more than a dozen to three.
Cache-related functions in JBLOG are stored in cache.func.php in the include directory. The main functions are:
/ / refresh cache function recache ($cachestr =') {if (! $cachestr) {$cachelist = array ('config','class','archive','newcomment','newpost','link','tag','statistic','topblog');} else {$cachelist = explode (',', $cachestr); foreach ($cachelist as $cache) {$cachename = $cache.'_recache'; if (function_exists ($cachename)) {$cachename ();}
The recache () function is used to refresh the cache. Each cache exists as a separate function, and the corresponding function needs to be executed only once when the cache is refreshed.
/ / write the string to the file function writeToFile ($cachename,$content =') {$allowcache = $cachelist = array ('config','class','archive','newcomment','newpost','link','tag','statistic','topblog'); if (in_array ($cachename,$allowcache)) {$cache_dir = JBLOG_ROOT.'cache_data/'; $cache_file_name = $cache_dir.'cache_'.$cachename.'.php' If (! is_dir ($cache_dir)) {@ mkdir ($cache_dir,0777)} if ($fp = @ fopen ($cache_file_name,'wb')) {$content = "