示例#1
0
 /**
  * @static
  * @param int $cachehost
  * @param int $cacheport
  * @param string $cacheType
  * @param string $cacheSys
  * @return db_Cache
  */
 public static function instance($cachehost = 0, $cacheport = 0, $cacheType = 'memcached', $cacheSys = '')
 {
     if (self::$self == NULL) {
         self::$self = new db_Cache($cacheSys, $cacheType, $cachehost, $cacheport);
     }
     return self::$self;
 }
示例#2
0
 /**
  * 主要check流程
  * @param string $key
  */
 public function check($key = NULL)
 {
     self::getkey($key);
     $ready = $this->cache->get($this->key);
     if ($ready == FALSE) {
         $this->cache->set($this->key, array(time()));
         return;
     }
     $ready_ = $ready;
     if (self::checkCountAndTime($ready_)) {
         $this->rest->error(rest_Code::STATUS_ERROR_API_QUENCY_M);
     }
     unset($ready_);
     array_push($ready, time());
     $this->cache->set($this->key, $ready);
 }
示例#3
0
 /**
  * 主要检测过程
  * @param int $time
  */
 public function ckModified($time = self::DEFAULT_MODIFIED_TIME)
 {
     if (!$this->ifConfig) {
         self::config($time);
     }
     $method = $_SERVER['REQUEST_METHOD'];
     switch ($method) {
         case 'GET':
             $uri = $_SERVER['REQUEST_URI'];
             $params = 0;
             break;
         case 'POST':
             $uri = $_SERVER['REQUEST_URI'];
             $params = $_POST;
             break;
     }
     $key = self::setModifiedKey($uri, $params);
     $cache_time = $this->cache->get($key);
     if ($cache_time) {
         if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
             $modified_time = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
             if ($cache_time <= $modified_time) {
                 self::mkHeader($cache_time);
                 header("HTTP/1.0 304 Not Modified");
                 die;
             }
         }
     } else {
         $now = time();
         $this->cache->set($key, $now, $this->modified_time);
     }
     self::mkHeader($now);
 }
示例#4
0
 private function __construct($dbhost, $dbport, $username, $password, $dbname, $dbcharset, $cachesys, $cachetype, $cachehost, $cacheport)
 {
     try {
         $this->_dbh = new PDO('mysql:host=' . $dbhost . ';port=' . $dbport . ';dbname=' . $dbname, $username, $password);
         $this->_dbh->query('SET NAMES ' . $dbcharset);
     } catch (PDOException $e) {
         exit('<pre><b>Connection failed:</b> ' . $e->getMessage());
     }
     $this->_cache = db_Cache::instance($cachehost, $cacheport, $cachetype, $cachesys);
     if (!$this->_cache) {
     }
 }