gordalina/cachetool-bundle

此包已被废弃,不再维护。未建议替代包。

CacheTool Symfony2 扩展包

1.7.0 2015-02-12 02:05 UTC

This package is auto-updated.

Last update: 2023-06-20 05:08:58 UTC


README

此扩展包允许您将 CacheTool 集成到 Symfony2。

安装

{
    "require": {
        "gordalina/cachetool-bundle": "~1.0"
    }
}

app/Appkernel.php 中注册扩展包

// app/AppKernel.php

public function registerBundles()
{
    return array(
        // ...
        new CacheTool\Bundle\CacheToolBundle(),
    );
}

app/config/config.yml 中启用扩展包的配置

# app/config/config.yml
cache_tool: ~

配置

有两种适配器

  1. CLI
# app/config/config.yml
cache_tool:
    adapter: cli
  1. FastCGI
# app/config/config.yml
cache_tool:
    adapter: fastcgi
    fastcgi: 127.0.0.1:900

您也可以通过 socket 连接,将上述内容替换为:/var/run/php5-fpm.sock

如果您不需要 apc 或 opcache,您可以将其设置为 false 以禁用它

# app/config/config.yml
cache_tool:
    apc: false
# app/config/config.yml
cache_tool:
    opcache: false

使用

命令

  cachetool:apc:bin:dump                   Get a binary dump of files and user variables
  cachetool:apc:bin:load                   Load a binary dump into the APC file and user variables
  cachetool:apc:cache:info                 Shows APC user & system cache information
  cachetool:apc:cache:info:file            Shows APC file cache information
  cachetool:apc:key:delete                 Deletes an APC key
  cachetool:apc:key:exists                 Checks if an APC key exists
  cachetool:apc:key:fetch                  Shows the content of an APC key
  cachetool:apc:key:store                  Store an APC key with given value
  cachetool:apc:sma:info                   Show APC shared memory allocation information
  cachetool:cache:clear:dump               Clears APC cache (user, system or all)
  cachetool:opcache:configuration          Get configuration information about the cache
  cachetool:opcache:reset                  Resets the contents of the opcode cache
  cachetool:opcache:status                 Show summary information about the opcode cache
  cachetool:opcache:status:scripts         Show scripts in the opcode cache

服务

您可以通过 cachetool 服务访问所有 apcopcode 函数。

$cache = $container->get('cachetool');
$cache->apc_clear_cache('both');
// or
$cache->opcache_reset();

扩展 CacheTool

CacheTool 依赖于 Proxies 来提供功能,默认情况下,从工厂创建 CacheTool 实例时,所有代理都被启用 ApcProxyOpcacheProxyPhpProxy,您可以自定义它或按需扩展,如下例所示

use CacheTool\Adapter\FastCGI;
use CacheTool\CacheTool;
use CacheTool\Proxy;

$adapter = new FastCGI('/var/run/php5-fpm.sock');
$cache = new CacheTool();
$cache->setAdapter($adapter);
$cache->addProxy(new Proxy\ApcProxy());
$cache->addProxy(new Proxy\PhpProxy());

您可以在 CacheTool 的页面了解更多信息。

许可证

此扩展包在 MIT 许可证下发布。 请参阅扩展包中的完整许可证。