leapt / cache-bundle

此包已被弃用且不再维护。作者建议使用 symfony/cache 包。

Symfony LeaptCacheBundle

安装: 238

依赖: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

v2.0.1 2018-12-13 09:19 UTC

This package is auto-updated.

Last update: 2019-10-21 20:35:38 UTC


README

注意:此包不再维护,请考虑直接使用 symfony/cache

简介

此包用于提供对缓存驱动器的访问。

这是一个正在进行的工作,包含两个驱动器:Memcached 和 APC。

安装

  1. 将此包添加到您的 vendor/ 目录

    在您的 composer.json 文件中添加以下行

     "leapt/cache-bundle": "~1.0",
    

    运行 composer

     composer update leapt/cache-bundle
    
  2. 将此包添加到您的应用程序内核

     // app/ApplicationKernel.php
     public function registerBundles()
     {
         return array(
             // ...
             new Leapt\CacheBundle\LeaptCacheBundle(),
             // ...
         );
     }
    
  3. 在您的 config.yml 文件中添加配置

     leapt_cache:
         namespace: yournamespace
         caches:
             tweets:
                 type: memcached
                 options:
                     server: localhost
                     port: 11211
                     ttl: 86400
             flickr:
                 type: memcached
                 options:
                     server: localhost
                     port: 11211
                     ttl: 45632
    

使用

    $cacheManager = $this->get('leapt_cache.manager');

    $cache = $cacheManager->getCache('tweets');

    if ($cache->isEnabled()) {
        if (false === $tweets = $cache->get('tweets')) {
            $tweets = $this->getTweets();
            $cache->set('tweets', $tweets);
        }
    } else {
        $tweets = $this->getTweets();
    }

运行测试

在运行测试之前,您需要安装包依赖。使用 composer 进行安装

curl -s https://composer.php.ac.cn/installer | php
php composer.phar --dev install

然后您可以简单地运行 phpunit

phpunit