Using data caching in Discuz

Source: Internet
Author: User
Tinkering with a few days Discuz cache, made a few clues, the efficiency is really low, 2333333~~~~

Discuz can use a variety of caches, and this is just about data caching. Discuz supports Redis, Memcache and other caching methods, as long as it is set up in/config/config_global.php, and the environment support can be used.

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

Require_once libfile (' Function/cache '); Load Cache class Savecache ($cachename, $data); Write Cache Loadcache (' plugin_fahao_kflist '); Reads the cache, writes the cache to the $_g variable, and fetches the cached data by reading the $_g[' cache '.

where Savecache () writes data to the set cache (such as MEMCACHE\REDIS\XPC, etc.) and logs the cache to the Common_syscache table.

When using Loadcache (), the Fetch_all method in the Table_common_syscache class is called to get the cache, 1, first determine whether the memory cache is set, if, read the memory cache data, there is data directly returned, Does not exist and does not set the memory cache to enter the 2nd step. 2, then determine whether to set the file cache, if, read the file cache data, there is a direct return of data, does not exist and does not set the file cache to enter the 3rd step. 3. Read the data from the Common_syscache table and return. (so you need to take care of these when clearing the cache)

The key is to clear the cache, in the global---performance optimization, memory optimization can do some settings optimization, in memory cache management can also directly clear the specified cache. But for a custom cache you need to develop the feature cleanup yourself. My environment is to open the Memcache cache, and then use the system's own memory () function to clear the cache, but when reading the data using Loadcache (), the cache is found to still exist. The reason is that memory () can clear out the memcache data, but does not clear the Commom_syscache table, so Loadcache () still exists. And then I checked. The Deletegroupcache () function was found. In order to adapt to the overall situation, the Deletecache () function has been simply written 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 describes the use of data caching in the Discuz, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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: 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.