[李景山php]thinkphp核心源码注释|Sqlite.class.php
来源:互联网 发布:淘宝dnfcdkey码怎么来 编辑:程序博客网 时间:2024/06/07 04:44
<?php// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.// +----------------------------------------------------------------------// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )// +----------------------------------------------------------------------// | Author: liu21st <liu21st@gmail.com>// +----------------------------------------------------------------------namespace Think\Cache\Driver;use Think\Cache;defined('THINK_PATH') or exit();/** * Sqlite缓存驱动 * 很小的一个数据库文件,不过不错,估计没什么大的创新 */class Sqlite extends Cache { /** * 架构函数 * @param array $options 缓存参数 * @access public * 架构 构造函数 */ public function __construct($options=array()) { if ( !extension_loaded('sqlite') ) { E(L('_NOT_SUPPORT_').':sqlite'); } if(empty($options)) { $options = array ( 'db' => ':memory:', 'table' => 'sharedmemory', ); } $this->options = $options; $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); $this->options['length'] = isset($options['length'])? $options['length'] : 0; $this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME'); $func = $this->options['persistent'] ? 'sqlite_popen' : 'sqlite_open'; $this->handler = $func($this->options['db']); } /** * 读取缓存 * @access public * @param string $name 缓存变量名 * @return mixed * */ public function get($name) { N('cache_read',1);// 记录 $name = $this->options['prefix'].sqlite_escape_string($name); $sql = 'SELECT value FROM '.$this->options['table'].' WHERE var=\''.$name.'\' AND (expire=0 OR expire >'.time().') LIMIT 1'; $result = sqlite_query($this->handler, $sql);// 看来你也是 sql 之中的一员啊 if (sqlite_num_rows($result)) { $content = sqlite_fetch_single($result);// 系统函数 if(C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) { //启用数据压缩 $content = gzuncompress($content); } return unserialize($content); } return false; } /** * 写入缓存 * @access public * @param string $name 缓存变量名 * @param mixed $value 存储数据 * @param integer $expire 有效时间(秒) * @return boolean */ public function set($name, $value,$expire=null) { N('cache_write',1); $name = $this->options['prefix'].sqlite_escape_string($name); $value = sqlite_escape_string(serialize($value)); if(is_null($expire)) { $expire = $this->options['expire']; } $expire=($expire==0)?0: (time()+$expire) ;//缓存有效期为0表示永久缓存 if( C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) { //数据压缩 $value = gzcompress($value,3); // var_dump( gzuncompress(gzcompress('lijingshan')) ); } $sql = 'REPLACE INTO '.$this->options['table'].' (var, value,expire) VALUES (\''.$name.'\', \''.$value.'\', \''.$expire.'\')'; if(sqlite_query($this->handler, $sql)){ if($this->options['length']>0) { // 记录缓存队列 $this->queue($name);// 队列记录 } return true; } return false; } /** * 删除缓存 * @access public * @param string $name 缓存变量名 * @return boolean * 同样需要数据表的一个支持呢 */ public function rm($name) { $name = $this->options['prefix'].sqlite_escape_string($name); $sql = 'DELETE FROM '.$this->options['table'].' WHERE var=\''.$name.'\''; sqlite_query($this->handler, $sql); return true; } /** * 清除缓存 * @access public * @return boolean * 为什么不直接清空数据表呢 */ public function clear() { $sql = 'DELETE FROM '.$this->options['table']; sqlite_query($this->handler, $sql); return ; }}// 总结,没什么特殊的了,
0 0
- [李景山php]thinkphp核心源码注释|Sqlite.class.php
- [李景山php]thinkphp核心源码注释|Sqlite.class.php
- [李景山php]thinkphp核心源码注释|View.class.php
- [李景山php]thinkphp核心源码注释|Think.class.php
- [李景山php]thinkphp核心源码注释|Template.class.php
- [李景山php]thinkphp核心源码注释|Storage.class.php
- [李景山php]thinkphp核心源码注释|Route.class.php
- [李景山php]thinkphp核心源码注释|Model.class.php
- [李景山php]thinkphp核心源码注释|Log.class.php
- [李景山php]thinkphp核心源码注释|Hook.class.php
- [李景山php]thinkphp核心源码注释|DB.class.php
- [李景山php]thinkphp核心源码注释|Controller.class.php
- [李景山php]thinkphp核心源码注释|Cache.class.php
- [李景山php]thinkphp核心源码注释|Build.class.php
- [李景山php]thinkphp核心源码注释|App.class.php
- [李景山php]thinkphp核心源码注释|Disaptcher.class.php
- [李景山php]thinkphp核心源码注释|Taglib.class.php
- [李景山php]thinkphp核心源码注释|Cx.class.php
- PHP数组问题
- C++中多态的实现原理
- java-03
- poj3122Pie(2)
- laravel 重命名/删除表
- [李景山php]thinkphp核心源码注释|Sqlite.class.php
- Java基础 常见List实现原理 - LinkedList
- [李景山php]thinkphp核心源码注释|Wincache.class.php
- JQUERY 网站
- 1231331321123133132112313313211231331321123133132112313313211231331321123133132112313313211231331321
- Myeclipse导入jeecg后pom.xml出错
- 无线实战视频
- datatable转实体
- IOC框架