pessek / pessek_stash
用于缓存常见计数器的API,以减少数据库查询
v4.0
2021-11-11 22:55 UTC
Requires
- php: >=7.4
- composer/installers: ^1.0.8
Conflicts
- elgg/elgg: <4.0
This package is not auto-updated.
Last update: 2024-09-28 10:21:56 UTC
README
用于缓存常见实体数据以减少数据库查询的API
- 缓存实体点赞数
- 缓存实体评论数
- 缓存最后评论
- 缓存用户好友数
- 缓存群组成员数
开发者备注
逻辑
该插件使用预加载类在首次请求时从数据库中加载数值。该值被缓存,并在后续调用时返回。可以使用 Preloader::up()
定义何时重置缓存值。例如,点赞数在创建新的点赞注释或删除旧的点赞注释之前是恒定的,因此我们为这些事件注册了我们的重置函数。
辅助函数
您可以使用辅助函数通过缓存框架检索计数。所有可用的快捷函数都可以在 /lib/functions.php
中找到
elgg_get_total_likes($entity); elgg_get_total_comments($entity); // etc.
自定义属性
$stash = \hypeJunction\Stash\Stash::instance(); // Register a new cacheable property $stash->register(new CustomProperty()); // Custom property must implement Preloader interface // Get property value $prop = $stash->get(CustomProperty::PROPERTY, $entity);