<?php class cache { var $cacheRoot = "./cache/"; var $cacheLimitTime = 3; var $cacheFileName = ""; var $cacheFileExt = "php"; function cache( $cacheLimitTime ) { if( intval( $cacheLimitTime ) ) $this->cacheLimitTime = $cacheLimitTime; $this->cacheFileName = $this->getCacheFileName(); ob_start(); } function cacheCheck(){ if( file_exists( $this->cacheFileName ) ) { $cTime = $this->getFileCreateTime( $this->cacheFileName ); if( $cTime + $this->cacheLimitTime > time() ) { echo file_get_contents( $this->cacheFileName ); ob_end_flush(); exit; } } return false; }
Generally speaking, the purpose of caching is to put data in one place to make access faster. There is no doubt that memory is the fastest, but can hundreds of M of data be stored in it? This is not the case In reality, of course, sometimes it is temporarily placed in the server cache. For example, if the ob_start() cache page is turned on, the page content will be cached in the memory before sending the file header, until the page output is automatically cleared or waiting for the return of ob_get_contents, [or Cleared by ob_end_clean, which can be well used in the generation of static pages and can be well reflected in templates
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article
13Jul2016
PHP file caching class,. PHP file cache class, 1 ? php 2 /* * 3 * @desc file cache 4 */ 5 class Cache{ 6 const C_FILE = '/Runtime/' ; 7 private $dir = '' ; 8 const EXT = '.tpl ' ; 9 private $filename = ''
13Jul2016
PHP file caching class example sharing,. PHP file cache class example sharing, copy the code as follows: php /** * @desc file cache*/ class Cache{ const C_FILE = '/Runtime/'; private $dir = ''; const EXT = '.tpl'; private
01Jun2023
As a popular server-side programming language, PHP often needs to handle large amounts of data and requests, so efficient cache management is crucial to improving website performance. This article will introduce how PHP uses caching, including the basic principles of caching, PHP's own caching methods and other popular caching libraries. 1. Basic principles of caching In web development, caching refers to saving frequently read data in a fast-access medium to reduce the time it takes to read data from a database or other resources for each request. When using cache, you first need to determine
11Jun2018
This article shares with you the code for the file caching class taken from ThinkPHP. It is very practical and efficient. It is recommended here for everyone to refer to if you need it.
01Dec2016
<?php /* * @(#)UploadFile.php * * Can handle multiple uploaded files by users at the same time. After verifying the validity of the file, store it in the specified directory. * Can return useful information about uploaded files for use by other programs. (Such as file name, type, size, save path) * Please see the information at the bottom of this class (UploadFile class usage notes) for usage methods. * */ class UploadFile { var $user_pos ...
13Jul2016
24 useful PHP libraries to share, 24php libraries. 24 useful PHP libraries to share, 24php libraries Currently, PHP is the most popular scripting language used for web development. You can easily find a lot of information about PHP on the Internet, including documentation, tutorials,
Hot Tools
PHP library for dependency injection containers
PHP library for dependency injection containers
A collection of 50 excellent classic PHP algorithms
Classic PHP algorithm, learn excellent ideas and expand your thinking
Small PHP library for optimizing images
Small PHP library for optimizing images