lioshi / wonder-cache-bundle
一个带有自动失效的全响应缓存。
Requires
- php: >=5.3.3
- ext-memcached: >=2.0
- symfony/framework-bundle: >=2.1
This package is not auto-updated.
Last update: 2024-09-28 15:12:18 UTC
README
这个 Symfony 2 扩展提供通过 doctrine 事件实现的带有自动失效的全响应缓存
- 只需一个服务调用即可管理操作的缓存
- 无需浪费时间去设置缓存失效系统
WonderCache 如何工作 WonderCache 
WonderCache 在请求时存在,绕过所有框架。作为一个代理。但WonderCache知道何时使缓存失效。
要求
- PHP 5.3.x 或更高版本
- php5-memcached 2.x
安装
使用 Composer 安装 WonderCacheBundle。只需将以下内容添加到您的 composer.json 文件中
{
require: {
"lioshi/wonder-cache-bundle": "dev-master",
...
}
}
接下来,通过执行以下命令安装扩展
php composer.phar update lioshi/wonder-cache-bundle
最后,将扩展添加到 app/AppKernel.php 文件中 AppKernel 类的 registerBundles 函数中
public function registerBundles()
{
$bundles = array(
...
new Lioshi\WonderCacheBundle\LioshiWonderCacheBundle(),
...
);
通过添加以下内容到 app/config/config.yml 来配置扩展
lioshi_wonder_cache: activated: true memcached_response: hosts: - { dsn: localhost, port: 11211 }
依赖
基于 Debian 的系统
apt-get install memcached php5-memcached
基于 CentOS 的系统
yum install php-pecl-memcached
添加 Memcache 模块后,不要忘记重新启动您的 Web 服务器。
命令
wondercache:clear
命令会删除所有缓存项,而 wondercache:list
命令可以列出所有缓存键,并可以显示所选键的内容。
完整配置
lioshi_wonder_cache: activated: true included_headers_keys: - email # Specify list of header's keys to include in url. Add only header's keys if page content return depends of. Or put ALL for all header's key memcached_response: hosts: - { dsn: localhost, port: 11211, weight: 60 } - { dsn: localhost, port: 11212, weight: 30 } options: compression: true serializer: 'json' prefix_key: "" hash: default distribution: 'consistent' libketama_compatible: true buffer_writes: true binary_protocol: true no_block: true tcp_nodelay: false socket_send_size: 4096 socket_recv_size: 4096 connect_timeout: 1000 retry_timeout: 0 send_timeout: 0 recv_timeout: 0 poll_timeout: 1000 cache_lookups: false server_failure_limit: 0
用法
在控制器中,您可以调用() WonderCache 并可选地指定与控制器响应关联的实体。以下示例表示控制器响应取决于(或与)
- 3 个具有 ID 1、65 和 988 的包
- 2 个具有 ID 65 和 22 的出口
- 所有汽车,并且它将在 3600 秒(默认持续时间是 0:无限)之前过期
控制器的示例代码
$this->container->get('wonder.cache')
->run()
->addLinkedEntities(
array(
'Me\MyBundle\Entity\Pack' => array(1,65,988),
'Me\MyBundle\Entity\Export' => array(65,22),
'Me\MyBundle\Entity\Cars' => array()
)
)
->addDuration(3600)
;
缓存失效系统
要查看缓存失效日志,只需在您的服务器中创建 /tmp/wcInvalidationCache.log 文件。
touch /tmp/wcInvalidationCache.log
这是一个滚动日志,其大小永远不会超过 1M 字节。
分析器的信息
使用 symfony 工具栏,您可以跟踪 WonderCache 的性能。如果有错误或警告
如果一切正常...
... 您可以看到更多关于 WonderCache 如何节省您时间的详细信息
致谢
受 https://github.com/LeaseWeb/LswMemcacheBundle 启发
- DependencyInjection/Configuration.php
- Command/ClearCommand.php