beryllium/cachebundle

为Symfony2应用程序提供Memcache接口

安装量: 134,961

依赖项: 0

建议者: 0

安全性: 0

星标: 32

关注者: 5

分支: 21

开放问题: 11

类型:symfony-bundle

v0.1.2 2013-04-02 22:42 UTC

This package is auto-updated.

Last update: 2024-09-06 15:02:26 UTC


README

这是memcache。您之前已经见过。现在它可以通过DIC注入,您不必自己编写所有这些垃圾代码。它还应该与Amazon ElasticCache以及MySQL Memcache接口(MySQL 5.6新增功能)一起工作。

与仅使用原始memcache对象相比,另一个优点是BCB在将服务器添加到池之前会探测服务器 - 如果服务器宕机,您的网站不会因为Memcache类长时间等待响应而受到严重影响。

还为您快速构建替代缓存接口奠定了基础 - 例如APC缓存或您自己的本地文件系统缓存。

配置

步骤1:获取

如果您使用composer,您可能只需要将其添加到您的composer.json文件中

"require": {
  "Beryllium/CacheBundle": "dev-master"
},

如果您不使用composer,将其添加到您的deps文件中

[BerylliumCacheBundle]
    git=http://github.com/beryllium/CacheBundle.git
    target=/bundles/Beryllium/CacheBundle

然后运行更新供应商脚本

bin/vendors install

步骤2:配置autoload.php

如果您不使用Composer,按照如下方式注册命名空间

# app/autoload.php

<?php

$loader->registerNamespaces( array(
  //...
  'Beryllium' => __DIR__.'/../vendor/bundles',
  ) );

步骤3:配置AppKernel

将其添加到您的AppKernel中

# app/AppKernel.php

<?php

    $bundles = array(
        //...
        new Beryllium\CacheBundle\BerylliumCacheBundle(),
    );

在parameters.ini中配置您的服务器列表

beryllium_cache.client.servers["127.0.0.1"] = 11211

或者对于parameters.yml

parameters:
    ...
    beryllium_cache.client.servers: { "localhost": 11211 }

如果您想更改默认缓存TTL值(300秒),您可以将其添加到您的parameters.yml中

parameters:
    ...
    beryllium_cache.default_ttl: 86400

如果您计划使用本地UNIX套接字,GitHub用户gierschv已经贡献了这项功能

beryllium_cache.client.servers["unix:///tmp/mc.sock"]=""

然后您就可以开始了

$this->get( 'beryllium_cache' )->set( 'key', 'value', $ttl );
$this->get( 'beryllium_cache' )->get( 'key' );

您可能需要设置一个服务别名,因为"$this->get('beryllium_cache')"可能有点长。

命令行

对于缓存客户端统计信息的命令行报告(假设缓存客户端有一个-getStats方法,这不是接口要求),您可以这样做

app/console cacheclient:stats

示例输出

Servers found: 1

Host:    127.0.0.1:11211
	Usage: 0% (0.01MB of 64MB)
	Uptime: 344976 seconds (3 days, 23 hours, 49 minutes, 36 seconds)
	Open Connections: 15
	Hits: 26
	Misses: 29
	Helpfulness: 47.27%

或者,要获取更多详细信息(原始统计数组),您可以启用调试模式运行

app/console cacheclient:stats --debug

帮助信息可用,尽管简短

app/console help cacheclient:stats

未来

目前还没有任何单元测试或功能测试。因此需要着手解决这个问题。

如果出现需求,更多的缓存客户端实现可能会有用。

是的,文档也需要更详细。我已经做了一些改进,但最多也只能说是零散的。

除此之外,谁知道未来会带来什么样的变化。

其他资源

MySQL InnoDB+Memcached API

Amazon ElastiCache