asgard/cache

v0.3.1 2016-05-13 11:31 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:55:44 UTC


README

#缓存

Build Status

Asgard\Cache 是 doctrine 缓存包的包装器。它提供了一些额外的功能。

##安装 如果你正在处理一个 Asgard 项目,你不需要安装这个库,因为它已经是标准库的一部分。

composer require asgard/cache 0.*

##Asgard 框架中的使用 缓存可以通过服务访问

$cache = $container['cache'];

要更改 Asgard 应用程序中的缓存驱动程序,请编辑 web/index.php 文件。

##框架外的使用

$cache = new \Asgard\Cache\Cache(new \Doctrine\Common\Cache\Cache);

##数组实现

你可以像访问数组一样访问缓存

$value = $cache['key'];
$cache['key'] => $value;
isset($cache['key']);
unset($cache['key']);

##默认结果

如果缓存无法获取你的键,它将返回并存储默认值。默认值也可以是一个回调,在这种情况下,结果将被返回并存储

$cache->fetch('key', 'default');
#or
$cache->fetch('key', function() {
	return 'default';
})

##NullCache

NullCache 允许你在不关心其激活的情况下使用缓存。值将不会存储,但使用缓存的代码将保持不变

$cache = new \Asgard\Cache\Cache(new \Asgard\Cache\NullCache());
$res = $cache->fetch('home', function() {
	return '<h1>Home</h1>';
});

如果缓存驱动程序不同,结果将在下一次调用缓存时存储和使用。

##命令

###清除缓存

清除缓存。

用法

php console cc

###贡献

请将所有问题和拉取请求提交到 asgardphp/asgard 仓库。

许可

Asgard 框架是开源软件,在 MIT 许可证 下授权。