Category cache refers to generating static files of website category content and storing them in a specified path. When users visit the category, the system reads the static files directly instead of generating pages dynamically, significantly improving access speed, reducing server load, and enhancing user experience.
In the PHPcms system, the category cache is usually stored in the /data/cache/columns/ directory under the root directory of the website. Each category corresponds to a folder named after the category's English identifier for easy management and access.
Log into the backend management system, navigate to “System” -> “Core Settings” -> “Website Settings”. In the “URL Settings” section, find “URL Rules”. Enable the “Enable Category Cache” option and set the “Category Cache Directory” to /data/cache/columns/. Save the settings to apply.
Category cache can be generated manually or automatically. Manual generation is available in the backend under “Update Cache” by selecting “Update Category Cache” and clicking the update button. Automatic generation can be set up through scheduled tasks to keep the cache updated.
The following example demonstrates how to manually generate the cache for a specified category via code:
<?php
defined('IN_PHPCMS') or exit('No permission resources.');
$catid = 1; // The ID of the category to generate cache for
$allowupdate = 1; // Permission to update cache
if ($allowupdate) {
pc_base::load_app_class('html', 'content');
$html = new html();
$html->category($catid); // Generate category cache
echo 'Category cache generated successfully!';
} else {
echo 'Cache update not allowed!';
}
?>
Category caching is a key mechanism in PHPcms for improving website performance. By caching category content as static files, page response speed is increased and server pressure is reduced. This article covered the cache storage path, configuration, and generation methods to provide developers with useful guidance for maintaining stable and efficient websites.