Home PHP Libraries Other libraries PHP class library for file caching
PHP class library for file caching
<?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

Disclaimer

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

PHP file caching class, _PHP tutorial PHP file caching class, _PHP tutorial

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 = ''

PHP file caching class example sharing, _PHP tutorial PHP file caching class example sharing, _PHP tutorial

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

php Http_Template_IT class library for template replacement_PHP tutorial php Http_Template_IT class library for template replacement_PHP tutorial

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

php auth_http class library for identity verification_PHP tutorial php auth_http class library for identity verification_PHP tutorial

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

PHP db class library for database operations_PHP tutorial PHP db class library for database operations_PHP tutorial

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)) {

PHP caching class for your own use, your own PHP caching class_PHP tutorial PHP caching class for your own use, your own PHP caching class_PHP tutorial

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

See all articles