epwt/cache-bundle

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

EPWT/Cache Symfony Bundle PSR-6 Cache Item Pool

安装: 10

依赖: 0

建议者: 0

安全: 0

星标: 2

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.0 2015-04-27 22:54 UTC

This package is auto-updated.

Last update: 2021-01-17 09:20:32 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License Analytics

SensioLabsInsight

EPWTCacheBundle 为 epwt/cache 库提供包装,并与 Symfony DependencyInjection 的魔法结合。

EPWT/Cache

EPWT/Cache 是符合 PSR-6 (是的,它只被提议) 的 CacheItemPool 实现,用于 Redis,也许将来还会支持其他缓存存储。

要求

安装

composer require epwt/cache-bundle "~1.0"
public function registerBundles()
{
	$bundles[] = new EPWT\CacheBundle\EPWTCacheBundle();
}

配置

所有 CacheItemPool 配置都是通过 Symfony Container 完成

当前支持的驱动程序

  • redis
  • sncredis

配置示例

Redis 驱动程序

<service id="acme.demo.items.pool" class="stdClass">
    <tag name="epwt_cache_pool" alias="acme_demo_pool" driver="redis" redis-id="acme.demo.redis"/>
</service>

SncRedis 驱动程序

<service id="acme.demo.items.pool" class="stdClass">
    <tag name="epwt_cache_pool" alias="acme_demo_pool" driver="snc_redis" sncredis-client="default"/>
</service>

附加选项

  • 如果您想,可以扩展 CacheItemPool 类并在 class 属性中指定它。
  • 默认情况下,CacheItemPool 的名称是 alias 属性值,但如果您想使用不同的名称,请使用 pool-name 属性指定。
  • 如果您想指定整个 CacheItemPool 的默认 TTL,请使用 default-ttl 属性,值是以秒为单位的设置值。

使用示例

  • 此包具有 CacheItemPoolsContainer 服务,ID 为 epwt_cache_pools
  • 此包还提供 CacheItemPoolsAwareTrait,需要 $this->getContainer 方法、$this->container 属性或 $this->get() 方法(仅在控制器中使用),并提供 getCacheItemPool($name) 方法以获取 CacheItemPool

使用 Trait

class HelloWorldCommand extends ContainerAwareCommand
{
    use CacheItemPoolsAwareTrait;

    protected function configure()
    {
        $this->setName('acme:hello');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $pool = $this->getCacheItemPool('acme_demo_pool');

        $poolItem = new CacheItem('foo');
        $poolItem->set('bar');

        $pool->save($poolItem);
    }
}

不使用 Trait

class HelloWorldCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this->setName('acme:hello');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $pool = $this->getContainer()->get('epwt_cache_pools')->get('acme_demo_pool');

        $poolItem = new CacheItem('foo');
        $poolItem->set('bar');

        $pool->save($poolItem);
    }
}

许可

此包受 MIT 许可证的约束。请参阅包中的完整许可证。

Resources/meta/LICENSE

关于

EPWTCacheBundle 由 Aurimas Niekis 提供。

报告问题或功能请求

问题和功能请求在 Github 问题跟踪器 中跟踪。

在报告bug时,将问题在基于Symfony标准版构建的基本项目中重现可能是个不错的主意,这样包的开发者可以通过简单地克隆项目并遵循一些步骤来重现问题。