SQLITE缓存
php
完整类源码
<?php /** * Sqlite缓存类 * @author WeakSun <52132522@qq.com> */ class Sqlite { static protected $handler; protected $options = array( 'table' => 'iCaches' ); /** * 架构函数 * @access public */ public function __construct($options = array()) { $this->options['prefix'] = isset($options['prefix']) ? $options['prefix'] : C('DATA_CACHE_PREFIX', null, ''); $this->options['expire'] = isset($options['expire']) ? $options['expire'] : C('DATA_CACHE_TIME', null, 36000); $this->options['nowTime'] = isset($GLOBALS['_beginTime']) ? $GLOBALS['_beginTime'] : microtime(true); $dbFile = TEMP_PATH . 'Caches.tmp'; $isCreate = is_file($dbFile); if (empty(static::$handler)) { static::$handler = new PDO("sqlite:{$dbFile}", null, null, array(PDO::ATTR_PERSISTENT => true)); empty($isCreate) && $this->exec("PRAGMA encoding = 'UTF8';PRAGMA temp_store = 2;PRAGMA auto_vacuum = 0;PRAGMA count_changes = 1;PRAGMA cache_size = 9000;"); $this->chkTable() || $this->createTable(); } } public function __destruct() { return $this->exec("DELETE FROM `{$this->options['table']}` WHERE `expire` < strftime('%s','now');VACUUM;"); } public function __call($method, $arguments) { if (method_exists(self::$handler, $method)) { return call_user_func_array(array(self::$handler, $method), $arguments); } else { E(__CLASS__ . ':' . $method . L('_METHOD_NOT_EXIST_')); return; } } /** * 读取缓存 * @access public * @param string $name 缓存变量名 * @return mixed */ public function get($name) { $id = $this->getName($name); $sth = static::$handler->query("SELECT `value` FROM `{$this->options['table']}` WHERE `id`='{$id}' AND `expire` > strftime('%s','now') LIMIT 1", PDO::FETCH_NUM); if (!empty($sth)) { N('cache_read', 1); list($data) = $sth->fetch(); return unserialize($data); } else { return false; } } /** * 写入缓存 * @access public * @param string $name 缓存变量名 * @param mixed $value 存储数据 * @param int $expire 有效时间 0为永久 * @return boolean */ public function set($name, $value, $expire = 0) { N('cache_write', 1); $data = serialize($value); if ($expire < 0 || $expire === false) { return true; } elseif (is_null($value) || $value === false) { return $this->rm($name); } elseif ($expire < 1) { $expire = 315360000; } $id = $this->getName($name); return $this->exec("REPLACE INTO `{$this->options['table']}` VALUES('{$id}','{$data}',{$expire}+strftime('%s','now'))"); } /** * 删除缓存 * @access public * @param string $name 缓存变量名 * @return boolean */ public function rm($name) { $id = $this->getName($name); return $this->exec("DELETE FROM `{$this->options['table']}` WHERE `id` = '{$id}'"); } /** * 清除缓存 * @access public * @param string $name 缓存变量名 * @return boolean */ public function clear() { return $this->exec("DELETE FROM `{$this->options['table']}`;"); } /** * 检查当前表是否存在 * @return bool 返回检查结果,存在返回True,失败返回False */ protected function chkTable() { return in_array($this->options['table'], $this->getTables()); } /** * 获取当前数据库的数据表列表 * @return array 返回获取到的数据表列表数组 */ protected function getTables() { $tables = $data = array(); $sth = $this->query("SELECT `name` FROM `sqlite_master` WHERE `type` = 'table' UNION ALL SELECT `name` FROM `sqlite_temp_master`"); if (!empty($sth)) { while ($row = $sth->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) { $tables[] = $row[0]; } unset($sth, $row); } return $tables; } /** * 创建当前数据表 * @return integer 成功返回1,失败返回0 */ protected function createTable() { return $this->exec("CREATE TABLE IF NOT EXISTS `{$this->options['table']}` (`id` VARCHAR PRIMARY KEY ON CONFLICT FAIL NOT NULL COLLATE 'NOCASE',`value` TEXT NOT NULL,`expire` INTEGER NOT NULL);"); } /** * 获取缓存名称 * @param string $name * @return string */ protected function getName($name) { if (!is_string($name) && !is_numeric($name)) { $name = md5(serialize($name)); } return $this->options['prefix'] . $name; } }
로그인 후 복사
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
2 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
Repo : 팀원을 부활시키는 방법
4 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
헬로 키티 아일랜드 어드벤처 : 거대한 씨앗을 얻는 방법
4 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
스플릿 소설을이기는 데 얼마나 걸립니까?
3 몇 주 전
By DDD
R.E.P.O. 파일 저장 위치 : 어디에 있고 그것을 보호하는 방법은 무엇입니까?
3 몇 주 전
By DDD

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제
Gmail 이메일의 로그인 입구는 어디에 있나요?
7335
9


자바 튜토리얼
1627
14


Cakephp 튜토리얼
1352
46


라라벨 튜토리얼
1264
25


PHP 튜토리얼
1209
29



이번 장에서는 CakePHP의 환경 변수, 일반 구성, 데이터베이스 구성, 이메일 구성에 대해 알아봅니다.

PHP 8.4는 상당한 양의 기능 중단 및 제거를 통해 몇 가지 새로운 기능, 보안 개선 및 성능 개선을 제공합니다. 이 가이드에서는 Ubuntu, Debian 또는 해당 파생 제품에서 PHP 8.4를 설치하거나 PHP 8.4로 업그레이드하는 방법을 설명합니다.

CakePHP는 PHP용 오픈 소스 프레임워크입니다. 이는 애플리케이션을 훨씬 쉽게 개발, 배포 및 유지 관리할 수 있도록 하기 위한 것입니다. CakePHP는 강력하고 이해하기 쉬운 MVC와 유사한 아키텍처를 기반으로 합니다. 모델, 뷰 및 컨트롤러 gu

VS Code라고도 알려진 Visual Studio Code는 모든 주요 운영 체제에서 사용할 수 있는 무료 소스 코드 편집기 또는 통합 개발 환경(IDE)입니다. 다양한 프로그래밍 언어에 대한 대규모 확장 모음을 통해 VS Code는
