【php开源代码栏目提醒】:本文主要为网学会员提供CacheFile.class.php,希望对需要CacheFile.class.php网友有所帮助,学习一下!
<?php
// +----------------------------------------------------------------------
// | Think
PHP // +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------------------------------------
* 鏂囦欢绫诲瀷缂撳瓨绫?
+------------------------------------------------------------------------------
* @category Think
* @package Think
* @subpackage Util
* @author liu21st <liu21st@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
class CacheFile extends Cache
{//绫诲畾涔夊紑濮?
/**
+----------------------------------------------------------
* 鏋舵瀯鍑芥暟
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
public function __construct($options='')
{
if(!empty($options['temp'])){
$this->options['temp'] = $options['temp'];
}else {
$this->options['temp'] = TEMP_PATH;
}
$this->expire = isset($options['expire'])?$options['expire']:C('DATA_CACHE_TIME');
if(substr($this->options['temp'], -1) != "/") $this->options['temp'] .= "/";
$this->connected = is_dir($this->options['temp']) && is_writeable($this->options['temp']);
$this->type = strtoupper(substr(__CLASS__,6));
$this->init();
}
/**
+----------------------------------------------------------
* 鍒濆鍖栨鏌?
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
private function init()
{
$stat = stat($this->options['temp']);
$dir_perms = $stat['mode'] & 0007777; // Get the per
mission bits.
$file_perms = $dir_perms & 0000666; // Remove execute bits for files.
// 鍒涘缓椤圭洰缂撳瓨鐩綍
if (!file_exists($this->options['temp'])) {
if (! mkdir($this->options['temp']))
return false;
chmod($this->options['temp'], $dir_perms);
}
}
/**
+----------------------------------------------------------
* 鏄惁杩炴帴
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
private function isConnected()
{
return $this->connected;
}
/**
+----------------------------------------------------------
* 鍙栧緱鍙橀噺鐨勫瓨鍌ㄦ枃浠跺悕
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @param string $name 缂撳瓨鍙橀噺鍚?
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
private function filename($name)
{
$name = md5($name);
if(C('DATA_CACHE_SUBDIR')) {
// 浣跨敤瀛愮洰褰?
$dir = $name{0};
if(!is_dir($this->options['temp'].$dir)) {
mkdir($this->options['temp'].$dir);
}
$filename = $dir.'/'.$this->prefix.$name.'.php';
}else{
$filename = $this->prefix.$name.'.php';
}
return $this->options['temp'].$filename;
}
/**
+----------------------------------------------------------
* 璇诲彇缂撳瓨
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $name 缂撳瓨鍙橀噺鍚?
+----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
public function get($name)
{
$filename = $this->filename($name)