ceeram/clear_cache

从Shell、应用或debug_kit面板清除CakePHP缓存

安装数量: 112,202

依赖: 3

建议者: 0

安全: 0

星标: 85

关注者: 13

分支: 16

公开问题: 2

类型:cakephp-plugin

1.1.0 2014-11-19 08:36 UTC

This package is auto-updated.

Last update: 2024-09-13 11:02:05 UTC


README

ClearCache插件提供了几种方法来清除CakePHP应用程序中的CACHE子文件夹和缓存引擎。

要求

主分支有以下要求

  • CakePHP 2.0或更高版本。
  • PHP 5.3.0或更高版本。

对于CakePHP 1.3,请使用1.3分支。

安装

  • 将此目录中的文件克隆/复制到app/Plugin/ClearCache
  • 确保通过调用CakePlugin::load('ClearCache');app/Config/bootstrap.php中加载插件

用法

控制台Shell

在您的APP文件夹中运行

# clear all cached files and configured engines
Console/cake ClearCache.clear_cache

# clear all cached files
Console/cake ClearCache.clear_cache files
# clear just files in CACHE folder
Console/cake ClearCache.clear_cache files .
# clear just files in CACHE subfolders
Console/cake ClearCache.clear_cache files *
# clear just files in CACHE/views folder
Console/cake ClearCache.clear_cache files views
# clear just files in selected CACHE subfolders
Console/cake ClearCache.clear_cache files models persistent

# clear all configured cache engines
Console/cake ClearCache.clear_cache engines
# clear just engine named _cake_core_
Console/cake ClearCache.clear_cache engines _cake_core_
# clear just selected engines
Console/cake ClearCache.clear_cache engines default sessions

# clear all configured cache groups
Console/cake ClearCache.clear_cache groups
# clear just cache group named comment
Console/cake ClearCache.clear_cache groups comment
# clear just selected groups
Console/cake ClearCache.clear_cache groups comment post

默认情况下,运行Shell将只显示清理的项的总数。使用-v标志获取已删除项的列表

# clear all cached files and configured engines
Console/cake ClearCache.clear_cache -v
# clear all cached files
Console/cake ClearCache.clear_cache files -v
# clear just engine named _cake_core_
Console/cake ClearCache.clear_cache engines _cake_core_ -v

库类

同样,从您的应用程序代码中运行

App::uses('ClearCache', 'ClearCache.Lib');
$ClearCache = new ClearCache();

$output = $ClearCache->run();

$output = $ClearCache->files();
$output = $ClearCache->files('.');
$output = $ClearCache->files('*');
$output = $ClearCache->files('views');
$output = $ClearCache->files('models', 'persistent');

$output = $ClearCache->engines();
$output = $ClearCache->engines('_cake_core_');
$output = $ClearCache->engines('default', 'custom');

$output = $ClearCache->groups();
$output = $ClearCache->groups('comment');
$output = $ClearCache->groups('comment', 'post');

files()方法返回一个关联数组,包含已删除/未删除的文件

array(
	'deleted' => array(...),
	'error'   => array(...)
)

engines()方法返回一个关联数组的结果

array(
	'default' => true,
	'_cake_core_'   => false
)

groups()方法返回一个关联数组的结果

array(
	'comment' => array(
		'default' => true,
	),
	'post' => array(
		'default' => true,
		'advanced' => true,
	),
)

run()方法返回一个关联数组的结果

array(
	'files' => array(
		'deleted' => array(...),
		'error'   => array(...)
	),
	'engines' => array(
		'default' => true,
		'_cake_core_'   => false
	)
)

DebugKit工具栏面板

在AppController中,配置使用ClearCache面板的DebugKit工具栏

public $components = array(
	'DebugKit.Toolbar' => array(
		'panels' => array('ClearCache.ClearCache')
	)
);

可选的,主要是在禁用调试且DebugKit配置为'forceEnable' => true的情况下,可以限制通过DebugKit面板仅清除CACHE子文件夹和缓存引擎/组的特定项(在文件夹/引擎/组键下的字符串或字符串数组)和/或使用特殊字符串all启用所有项

public $components = array(
	'DebugKit.Toolbar' => array(
		'panels' => array('ClearCache.ClearCache'),
		'clear_cache' => array(
			// allow to clear just files in CACHE/views folder
			'folders' => 'views'
			// allow to clear all cache engines at once, and selected ones separately
			'engines' => array('_all_', 'default', 'sessions'),
			// allow to clear all cache groups at once, and selected ones separately
			'groups' => array('_all_', 'comment', 'post'),
		)
	)
);

清除缓存组

缓存组是在CakePHP 2.2中引入的,并且它们在使用相同引擎和相同前缀的所有缓存配置中共享。尽管如此,ClearCache插件清除整个缓存组 - 即使它们在具有不同缓存引擎和不同前缀的缓存配置中指定。