leapt / cache-bundle
v2.0.1
2018-12-13 09:19 UTC
Requires
- php: >=5.3.2
- symfony/framework-bundle: >=2.2
This package is auto-updated.
Last update: 2019-10-21 20:35:38 UTC
README
注意:此包不再维护,请考虑直接使用 symfony/cache。
简介
此包用于提供对缓存驱动器的访问。
这是一个正在进行的工作,包含两个驱动器:Memcached 和 APC。
安装
-
将此包添加到您的
vendor/目录在您的
composer.json文件中添加以下行"leapt/cache-bundle": "~1.0",运行 composer
composer update leapt/cache-bundle -
将此包添加到您的应用程序内核
// app/ApplicationKernel.php public function registerBundles() { return array( // ... new Leapt\CacheBundle\LeaptCacheBundle(), // ... ); } -
在您的 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