<?php class CacheLayer{ protected $root = ""; protected $cache = ""; protected $key = ""; protected $life = 0; public function __construct($key, $root = "/cachelayer"){ $this->root = $_SERVER["DOCUMENT_ROOT"].$root; $this->key = $key; } public function expired($life_span){ $this->life = $life_span; $file = $this->root."/".$this->key.".cachelayer"; if(is_file($file)){ $mtime = filemtime($file); return (time() >= ($mtime + $this->life)); }else{ return true; } } public function put($content){ $file = $this->root."/".$this->key.".cachelayer"; if(!is_dir(dirname($this->root))){ return false; } $this->delete(); $content = json_encode($content); return (bool)file_put_contents($file, $content); } public function get(){ $file = $this->root."/".$this->key.".cachelayer"; if(is_file($file)){ return json_decode(file_get_contents($file), true); } return array(); } public function delete(){ $file = $this->root."/".$this->key.".cachelayer"; if(is_file($file)){ unlink($file); return true; } return false; } } ?>
This is a very useful PHP caching library. Friends who need it can download and use it. It can greatly relieve the pressure on the database through file caching
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
13 Jul 2016
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 = ''
13 Jul 2016
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
21 Jul 2016
php Http_Template_IT class library for template replacement. Two simple templates: Copy code The code is as follows: html head title{title}/title /head body font color=red size=6center{title}/center/font hr pre{body}/pre /body /html Copy code Code
21 Jul 2016
php auth_http class library for identity verification. Copy the code as follows: ?php require_once("Auth/HTTP.php"); //Set the database connection options $auth_options=array( 'dsn'="mysql://root:1981427@localhost/test", // Database connection word
21 Jul 2016
PHP db class library performs database operations. Copy the code as follows: ?php require_once "DB.php"; //Contains class library files $conn = DB::connect("mysql://root:1981427@localhost/test"); //Connect to the database if (! DB::isError($conn)) {
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
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