hypejunction/hypestash

此包已被废弃,不再维护。未建议替代包。

API 用于缓存常见计数以减少数据库查询

安装: 36

依赖: 1

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

类型:elgg-plugin

1.0.2 2018-10-16 10:00 UTC

This package is not auto-updated.

Last update: 2020-01-18 13:22:34 UTC


README

Elgg 3.0

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);