Use data cache in discuz

Source: Internet
Author: User
: This article describes how to use data caching in discuz. if you are interested in the PHP Tutorial, refer to it. After a few days of discuz caching, I found some clues, which is really inefficient. 2333333 ~~~~

Discuz can use multiple caches. here we only talk about data caching. Discuz supports cache methods such as redis and memcache. you only need to set it in/config/config_global.php and the environment supports it.

In fact, the read/write cache is relatively simple. the code is as follows:

Require_once libfile ('function/cache'); // load the cache class savecache ($ cachename, $ data); // write the cache loadcache ('In in _ fahao_kflist '); // read the cache, write the cache to the $ _ G variable, and obtain the cached data by reading $ _ G ['cache.

Specifically, savecache () writes data to the set cache (such as memcache \ redis \ xpc), and records the cache to the common_syscache table.

When loadcache () is used, the fetch_all method in the table_common_syscache class is called to obtain the cache. 1. First, determine whether the memory cache is set. If yes, read the data cached in the memory, if data exists and no memory cache is set, go to step 1. 2. check whether the file cache is set. if the file cache data is read, data is returned directly. if the file cache does not exist or the file cache is not set, go to step 2. 3. Read and return data from the common_syscache table. (These aspects must be taken into account when clearing the cache)

The key is to clear the cache. in global-> performance optimization-> memory optimization, you can perform some settings optimization. in memory cache management, you can also directly clear the specified cache. However, the custom cache needs to be cleared by the development function. In my environment, I enabled the memcache cache and used the built-in memory () function to clear the cache. However, when I read data using loadcache (), I found that the cache still exists. The reason is that memory () can clear memcache data, but does not clear the commom_syscache table, so loadcache () still exists. Later, I found the deletegroupcache () function. To adapt to the global situation, you have simply written the deletecache () function in/source/function/function_core.php. The code is as follows:

function deletecache($cachenames) {if(!empty($cachenames)) {C::t('common_syscache')->delete($cachenames);}}

The above introduces the use of data caching in discuz, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

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.