kitpages / simple-cache-bundle
非常简单的symfony2缓存系统。缓存数据保存在数据库中的一个表中。
v3.0.0
2013-09-09 12:13 UTC
Requires
- doctrine/orm: ~2.1
- symfony/framework-bundle: ~2.1
Requires (Dev)
- beberlei/doctrineextensions: dev-master
- symfony/class-loader: ~2.1
- symfony/finder: ~2.1
- symfony/yaml: ~2.1
This package is auto-updated.
Last update: 2024-09-04 19:33:23 UTC
README
非常简单的symfony2缓存系统。缓存数据保存在数据库中的一个表中。
作者:Philippe Le Van (twitter: @plv) http://www.kitpages.fr/fr/cms/102/kitpagessimplecachebundle
安装
嗯...像往常一样...
将代码放入 vendors/Kitpages/SimpleCacheBundle
在 app/autoload.php 中添加 vendors/
在 app/appKernel.php 中添加新的 Bundle
您需要创建一个数据库表
CREATE TABLE `simple_cache_backend` (
`id` varchar(255) NOT NULL,
`data` longtext COMMENT '(DC2Type:array)',
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
`expired_at` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
(或者您可以使用 php app/console doctrine:schema:update)
用户指南
1/ 记录到缓存中并从缓存中检索
$cacheManager = $this->get('kitpages.simple_cache');
$html = $cacheManager->get(
'my-cache-uniq-id-12',
function() {
$output = "hello world";
sleep (3);
return $output;
}
);
2/ 清除缓存
$cacheManager = $this->get('kitpages.simple_cache');
$cacheManager->clear('my-cache-uniq-id-12');
3/ 更复杂的一个例子:传递给回调的参数和过期时间
$html = $cacheManager->get(
'my-cache-uniq-id-12',
function($arg1, $arg2) {
$output = "hello world";
sleep (3);
return $output;
},
array(12, 34),
$myExpirationTimeInSeconds
);
4/ 缓存中的多个删除
$cacheManager = $this->get('kitpages.simple_cache');
$cacheManager->clear('my-cache-%');
// remove all the entries in the cache beginning by "my-cache-"