thinkPHP 5.0.x 使用SQLite3 进行缓存设置 Cache

thinkphp5.0 sqlite3. cache

1. 配置 thinkPHP cache [application/config.php]

config.php文件的cache设置

  • type设置为sqlite3(默认是小写,第一个字母不区分大小写)
  • path换成db,并指定sqlite3数据库文件的位置

2. 添加drive类

  • 如果你打开了app_debug你会看到并没有Sqlite3的驱动,cache的驱动都在library/library/think/cache/driver/目录下,其中的sqlite不支持SQLite3数据库类型。所以需要自己新建一个Sqlite3.php类,大概为

Sqlite3类实现

我大概实现了这个类,文件可以在这里下载,然后上传到 library/library/think/cache/driver/目录下

3. 设置数据库

假如的你数据库名字为 sharedcache.db
默认表格为sharedmemory,你可以在 配置中配置table来定义表名。

var value expire tag
text blob int text
# in runtime/cache
> sqlite3 sharedcache.db
sqlite> create table sharedmemory (var text unique not null, value blob default null, expire int default 0, tag text  default null);
sqlite> .tables #查看新建是否成功
sqlite> .headers on #显示表格头部
sqlite> select * from sharedmemory;

现在可以使用了

如果你之前使用的File或其他方式,记得把缓存迁移过来。

引用

  1. http://stackoverflow.com/questions/15727466/php-inserting-blob-image-to-sqlite-table
posted @ 2016-12-03 01:25  乌祁班岚图  阅读(1299)  评论(0编辑  收藏  举报