search
Homephp教程php手册修改ThinkPHP缓存为Memcache的方法

这篇文章主要介绍了修改ThinkPHP缓存为Memcache的方法,需要的朋友可以参考下

一般来说,ThinkPHP的默认缓存方式是以File文件方式实现的,运行时会在/Runtime/Temp 下生成很多的缓存文件。
有的情况下服务器装了memcached之后,需要将ThinkPHP的缓存方式更改成memecache方式
具体操作步骤如下:

在Conf/config.php 中添加:

'DATA_CACHE_TYPE' => 'Memcache', 'MEMCACHE_HOST' => 'tcp://127.0.0.1:11211',

更新缓存后刷新页面发现缓存并没有生效。
得到调试信息:

[ 2010-09-30T11:41:56+08:00 ] NOTIC: [8] MemcachePool::set(): Server 127.0.0.1 (tcp 11211, udp 0) failed with: CLIENT_ERROR bad command line format (0) CacheMemcache.class.php 第 107 行.

于是找到这句:

return $this->handler->set($name, $value, 0, $expire);

进一步调试之后发现 $expire 的值是-1; 写程序的时候并没有指定缓存的时长,这里的-1可能不被memcached接受。
于是在Conf/config.php 中添加:

'DATA_CACHE_TIME' => '3600',

指定默认的缓存时长为3600 秒; 再运行,错误没有了,缓存成功!

另外,,需要在某个action里清除所有缓存的时候可以这样实现: 

$cache = Cache::getInstance(); $cache ->clear();

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)