phpsed / cache
Symfony 响应缓存
Requires
- php: ^7.1.3
- doctrine/annotations: ~1.6
- doctrine/dbal: ~2.6
- doctrine/orm: ~2.6
- predis/predis: ~1.1
- psr/cache: ^1
- symfony/cache: ~3.2|~4.0
- symfony/config: ~3.2|~4.0
- symfony/dependency-injection: ~3.2|~4.0
- symfony/event-dispatcher: ~3.2|~4.0
- symfony/http-foundation: ~3.2|~4.0
- symfony/http-kernel: ~3.2|~4.0
Suggests
- snc/redis-bundle: For easier Predis client configuration
This package is auto-updated.
Last update: 2020-11-14 16:44:07 UTC
README
我没有时间继续开发了,所以我的朋友接手了: vairogs/cache
README 对于 2.x-dev 版本不是最新的!
有人关于这个仓库制作了Medium文章,请在这里查看:这里!
Phpsed cache 是基于注解的控制器响应缓存,用于 Symfony 框架。它从 GET 和 POST 参数生成特定的路由键,并将其保存在提供的缓存客户端中。
目前支持客户端是 Predis 和 DoctrineOrm。
phpsed_cache: enabled: FALSE|true providers: - snc_redis.session - doctrine.orm.default_entity_manager
默认情况下,enabled 参数设置为 false,这意味着如果不将其设置为 true,@Cache 注解将不会工作。
providers 必须是 Predis 或 Doctrine Orm 客户端。
在上面的示例中,提供了两个提供者
Predis 客户端来自 snc/redis-bundle => snc_redis.session 和 Doctrine 实体管理器 => doctrine.orm.default_entity_manager。
如果 enabled 参数设置为 true,至少必须提供一个有效的提供者。
Phpsed\Cache 使用 Symfony\Cache ChainAdapter
When an item is not found in the first adapter but is found in the next ones, this adapter ensures that the fetched item is saved to all the adapters where it was previously missing.
use Phpsed\Cache\Annotation\Cache; use Symfony\Component\Routing\Annotation\Route; @Route("/{id}", name = "default", defaults = {"id" = 1}, methods = {"GET", "POST"}) @Cache( expires = 3600, attributes = {"id"} )
默认情况下,@Cache 注解不需要任何参数。
如果没有 attributes 参数,缓存键将使用所有 GET 和 POST 参数生成。
如果没有 expires 参数,缓存将保存为无限 TTL,这意味着它将一直有效,直到被删除。
如果 GET 和 POST 中存在相同的参数,则使用 GET 参数的值。
@Cache 注解接受两个可选参数:expires 和 attributes。
expires 设置给定缓存的最高 TTL。
在上面的示例中,缓存将保存 3600 秒,并在 3600 秒后失效。
如果设置了 attributes 参数,并且给定的属性存在于 GET 或 POST 参数中,则只使用给定的参数作为缓存键。只有在创建键时使用有效属性。如果给定的属性不存在,则键将不带任何参数生成。
PS-CACHE: PS-CACHE-DISABLE
为了使端点的缓存失效和删除,您必须通过调用该端点并带有特定头来实现。为此,您需要设置 PS-CACHE 头为 PS-CACHE-DISABLE 值。