background image

一个强大的 PHP 缓存类

强大的 PHP 缓存类(支持基于文件缓存和 eaccelerator、apc、xcache、memcache 模块缓存)

 
 
 
直接贴代码:
 

<?php

/*
 * Name:    wrapperCache
 * URL:     http://www.admpub.com/
 * Version: v0.1
 * Date:    29/10/2010
 * Author:  Chema Garrido
 * License: GPL v3
 * Notes:   wrapper cache for fileCache, memcache, APC, Xcache and eaccelerator
 */
 
/////////////////////class file cache
 
class wrapperCache {
        private   $cache_params;//extra   params   for   external   caches   like   path   or   connection   option 
memcached
    public $cache_expire;//seconds that the cache expires
    private $cache_type;//type of cache to use
    private $cache_external; //external instance of cache, can be fileCache or memcache
    private static $instance;//Instance of this class
        
    // Always returns only one instance
    public static function GetInstance($type='auto',$exp_time=3600,$params='cache/'){
        if (!isset(self::$instance)){//doesn't exists the isntance
             self::$instance = new self($type,$exp_time,$params);//goes to the constructor
        }
        return self::$instance;
    }
    
    //cache constructor, optional expiring time and cache path
    private function __construct($type,$exp_time,$params){
        $this->cache_expire=$exp_time;
        $this->cache_params=$params;
        $this->setCacheType($type);
    }