<?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
06 Jul 2016
What are some very useful class libraries or tool libraries for PHP?
12 Jul 2016
My own PHP caching class, my own PHP caching class. PHP cache class for your own use, your own PHP cache class?php/** * Cache class, data implementation, output cache* @author ZhouHr 2012-11-09 http://www.ketann.com * @copyright version 0.1 */ class C
11 Jan 2025
Hello everyone! Is your application running slowly due to repetitive database queries? Or have trouble switching between different caching libraries? Let’s dive into PSR-6, the standard that makes caching in PHP predictable and interchangeable! This article is part of the PHPPSR standards series. If you are new to this, you may want to start with PSR-1 basics. What problem does PSR-6 solve? (2 minutes) Before PSR-6, each cache library had its own unique way of working. Want to switch from Memcached to Redis? Rewrite your code. Migrating from one framework to another? Learn the new caching API. PSR-6 solves this problem by providing a common interface that all cache libraries can implement. nuclear
12 Nov 2024
Memcache vs. Memcached: Choosing the Right PHP Library for Your Cache NeedsIn the realm of PHP caching libraries, Memcache and Memcached stand out...
13 Dec 2024
Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...
11 Nov 2024
Hidden Truths: The Leading Underscore in PHP Class MethodsWhen browsing PHP libraries, one might stumble upon class methods prefixed with a...
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