国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

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

How Do I Link Static Libraries That Depend on Other Static Libraries? How Do I Link Static Libraries That Depend on Other Static Libraries?

13 Dec 2024

Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...

PHP file dual purpose: best practices for front-end API and back-end library PHP file dual purpose: best practices for front-end API and back-end library

05 Aug 2025

This article will explore in-depth how to optimize PHP files so that they can serve as both an API interface for front-end AJAX requests and a function library that can be safely referenced by back-end PHP scripts. We will analyze common problems, such as accidental execution of complete logic when a file is included, and provide various strategies such as conditional judgment, modular design, and consistent parameter management to ensure the clearness, efficiency and maintainability of the code, while taking into account the different needs of front-end and back-end calls.

How to Silence TensorFlow\'s Debugging Output? How to Silence TensorFlow\'s Debugging Output?

28 Oct 2024

Suppression of Tensorflow Debugging OutputTensorflow prints extensive information about loaded libraries, found devices, and other debugging data...

How Does jQuery Simplify DOM Manipulation for Web Developers? How Does jQuery Simplify DOM Manipulation for Web Developers?

03 Jan 2025

Overflow: Hidden and Expansion of HeightjQuery distinguishes itself from other JavaScript libraries through its cross-platform compatibility and...

How to Create and Utilize Static Libraries in g  ? How to Create and Utilize Static Libraries in g ?

24 Oct 2024

This article guides developers on crafting static libraries in C using g . It demonstrates how to compile source code into object files, create static libraries, and incorporate them into other projects. By leveraging this approach, developers can

Which native Java image processing library is right for you? Which native Java image processing library is right for you?

30 Oct 2024

Native Java Image Processing Libraries for High-Quality ResultsAs you have encountered limitations with ImageMagick and JAI, let's explore other...

See all articles