icybee/module-cache

提供通用的API和集中式管理缓存的地点。

安装: 705

依赖关系: 4

建议者: 1

安全性: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:icanboogie-module

v3.0.0 2016-05-24 21:58 UTC

This package is auto-updated.

Last update: 2024-09-20 01:58:15 UTC


README

缓存模块(cache)提供通用的API和集中式管理缓存的位置。

该模块包含框架ICanBoogie的缓存管理器。

缓存管理器

创建自己的缓存管理器

您可以使用“cache”模块的任何类型的缓存,您的管理器只需扩展CacheManagerBase类或实现CacheManager接口。

以下属性也必须提供

  • (string) title: 缓存的标题。标题在cache.title作用域内进行翻译。
  • (string) description: 缓存的描述。描述在cache.description作用域内进行翻译。
  • (string) group: 缓存按组显示。可以使用此属性定义缓存的组。组在cache.group作用域内进行翻译。
  • (bool) state: 缓存是否启用。
  • (int|bool) size_limit: 缓存的大小限制,或如果不适用的false
  • (int|bool) time_limit: 缓存条目的时间限制,或如果不适用的false
  • (string|null) config_preview: 缓存配置的预览,或不适用的null
  • (string) editor: 配置编辑器,或不适用时为null

注意:由于config_previeweditor属性很少使用,建议使用getter返回其值

<?php

use ICanBoogie\Accessor\AccessorTrait;

abstract class CacheManagerAbstract implements Icybee\Modules\Cache\CacheManager
{
	use AccessorTrait;

	protected function get_config_preview()
	{
		// …
	}

	protected function get_editor()
	{
		// …
	}
}

注册您的缓存管理器

缓存管理器在Icybee\Modules\Cache\CacheCollection::collect事件上注册。例如,这是“views”模块使用hooks配置注册其缓存管理器的方式

<?php

// hooks.php

namespace Icybee\Modules\Views;

$hooks = Hooks::class . '::';

return [
	'events' => [
		'Icybee\Modules\Cache\CacheCollection::collect' => $hooks . 'on_cache_collection_collect',
		// ...
	],
	// ...
];

事件

Icybee\Modules\Cache\CacheCollection::collect

第三方可以使用Icybee\Modules\Cache\CacheCollection\CollectEvent类的事件来注册其缓存管理器。该事件在缓存集合构造期间触发。

以下代码是向缓存集合添加icybee.views缓存的示例

<?php

namespace Icybee\Modules\Views;

use Icybee\Modules\Cache\CacheCollection as CacheCollection;

class Hooks
{
	// …

	static public function on_cache_collection_collect(CacheCollection\CollectEvent $event, CacheCollection $collection)
	{
		$event->collection['icybee.views'] = new ViewCacheManager;
	}

	// …
}

原型方法

ICanBoogie\Application::get_caches

get_caches获取器添加到ICanBoogie\Application类的实例中,它返回缓存集合。

<?php

/* @var \ICanBoogie\Application $app */

$app->caches['core.modules']->clear();

操作

缓存操作需要将缓存标识符定义为操作的键。例如,要清除core.modules缓存,则使用操作POST /api/cache/core.modules/clear

Icybee\Modules\Cache\ClearOperation

清除指定的缓存。

Icybee\Modules\Cache\ConfigureOperation

配置指定的缓存。

Icybee\Modules\Cache\DisableOperation

禁用指定的缓存。

Icybee\Modules\Cache\EditorOperation

返回配置编辑器。

编辑器通过缓存的editor属性获取。

Icybee\Modules\Cache\EnableOperation

启用指定的缓存。

在启用缓存之前清除缓存。

Icybee\Modules\Cache\StatOperation

返回指定缓存的用法(内存、文件)。

事件钩子

Icybee\Modules\Modules\ActivateOperation::process

在激活模块时清除ICanBoogie的缓存。

Icybee\Modules\Modules\DeactivateOperation:process

在停用模块时清除ICanBoogie的缓存。

需求

该包需要PHP 5.6或更高版本。

安装

安装此包的推荐方法是使用Composer

$ composer require icybee/module-cache

克隆存储库

该包可在GitHub上获取(点击访问),可以使用以下命令行克隆其仓库:

$ git clone https://github.com/Icybee/module-cache.git

文档

该包作为Icybee CMS文档的一部分进行了文档化(点击访问)。可以使用make doc命令生成该包及其依赖的文档。文档使用ApiGen生成,生成的文档位于docs目录。之后可以使用make clean命令清理包目录。

许可证

该模块采用新BSD许可证授权 - 详细信息请参阅LICENSE文件。