Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common caching techniques in PHP

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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 = "

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report