2PHP Cache Type

Source: Internet
Author: User
2PHP Cache Classes
 Cachecheck (); Echo Date ("y-m-d h:i:s");//$cache->clearcache (' mv_moves.php '); $cache->caching (); */class Cache {  Cache directory var $cacheRoot = "./cache/";  Cache update time seconds, 0 is not cached var $cacheLimitTime = 0;  Cache filename var $cacheFileName = "";   Cache extension var $cacheFileExt = "PHP";      /* * constructor * int $cacheLimitTime Cache Update Time */function cache ($cacheLimitTime) {if (Intval ($cacheLimitTime))    $this->cachelimittime = $cacheLimitTime;    $this->cachefilename = $this->getcachefilename ();  Ob_start (); }/* * Check that the cache file is returned within the SET update time *: If the contents of the file are returned within the update time, the reverse returns the failure */function Cachecheck () {if (File_exists ($this->ca      Chefilename) {$cTime = $this->getfilecreatetime ($this->cachefilename);        if ($cTime + $this->cachelimittime > Time ()) {echo file_get_contents ($this->cachefilename);        Ob_end_flush ();      Exit  }} return false; }/* * cache file or output static * string $staticFileName static file name (with relative path) */function Caching ($staticFileName = "") {if ($this->cachefilename) {$cacheContent = Ob_get_contents ();      Echo $cacheContent;       Ob_end_flush ();      if ($staticFileName) {$this->savefile ($staticFileName, $cacheContent);    } if ($this->cachelimittime) $this->savefile ($this->cachefilename, $cacheContent); }/* * Clear Cache file * String $fileName Specify file name (with function) or all * return: Clear successfully returns TRUE, vice versa * * Function ClearCache ($file Name = "All") {if ($fileName! = "All") {$fileName = $this->cacheroot. Strtoupper (MD5 ($fileName)). ".".      $this->cachefileext;      if (file_exists ($fileName)) {return @unlink ($fileName);    }else return false; if (Is_dir ($this->cacheroot)) {if ($dir = @opendir ($this->cacheroot)) {while ($file = @r          Eaddir ($dir)) {$check = Is_dir ($file);        if (! $check) @unlink ($this->cacheroot. $file); } @cloSedir ($dir);      return true;      }else{return false;    }}else{return false; The cache filename is generated from the current dynamic file */function Getcachefilename () {return $this->cacheroot. Strtoupper (MD5 ($_server ["Request_uri"]). ".".  $this->cachefileext; }/* * Cache File setup Time * string $fileName cache filename (with relative path) * Returned: File generation time in seconds, file does not exist return 0 */function getfilecreatetime ($fileNa     Me) {if (! Trim ($fileName)) return 0;    if (file_exists ($fileName)) {return intval (Filemtime ($fileName));  }else return 0; }/* * Save File * String $fileName file name (with relative path) * String $text file Contents * Return: Ture returned successfully, failed to return false */function SAVEF     Ile ($fileName, $text) {if (! $fileName | |! $text) return false; if ($this->makedir (dirname ($fileName))) {if ($fp = fopen ($fileName, "w")) {if (@fwrite ($FP, $tex          T)) {fclose ($FP);        return true;          }else {fclose ($FP);        return false; }}} RETUrn false; }/* * Continuous Directory * String $dir directory String * int $mode Permission number * return: Successfully created or all built returns True, other methods return false */function MakeDir ($d    IR, $mode = "0777") {if (! $dir) return 0;        $dir = str_replace ("\ \", "/", $dir);    $mdir = ""; foreach (Explode ("/", $dir) as $val) {$mdir. = $val. "      /";            if ($val = = ":" | | $val = = "." | | Trim ($val) = = "") continue;        if (! file_exists ($mdir)) {if ([email protected] ($mdir, $mode)) {return false;  }}} return true; }}?>
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.