soflomo / cache
Zend Framework 2中的缓存管理命令行工具
Requires
- php: >=5.3.3
- zendframework/zend-cache: ~2.0
- zendframework/zend-mvc: ~2.0
This package is not auto-updated.
Last update: 2024-09-14 16:08:24 UTC
README
Soflomo\Cache是Zend Framework 2中用于缓存管理的命令行工具。它允许您从命令行管理您的Zend\Cache实例,包括:
- 打印所有可用缓存服务的列表
- 获取所有服务的状态(总空间,可用空间)
- 清除完整的缓存实例
- 通过过期项清除缓存
- 通过命名空间清除缓存
- 通过前缀清除缓存
- 移除ZF2应用程序缓存:合并的配置和模块映射文件
安装
Soflomo\Cache与Composer一起使用。请确保您已下载composer.phar,并在您项目的根目录下有一个composer.json
文件。要安装它,请在您的composer.json
文件中添加以下行
"require": {
"soflomo/cache": "~0.2"
}
安装包后,您需要通过将Soflomo\Cache
添加到您的application.config.php
文件中来启用该模块。
要求
- Zend Framework 2:的
Zend\Cache
组件 - Zend Framework 2:的
Zend\Mvc
组件
配置
Soflomo\Cache会自动扫描配置中的可用缓存列表。此键用于将缓存定义为服务。如果您想使用此键,您必须将缓存注册为抽象工厂
'service_manager' => array( 'abstract_factories' => array( 'Zend\Cache\Service\StorageCacheAbstractServiceFactory', ), ),
使用Soflomo\Cache,您不必强制使用缓存抽象工厂。唯一的前提是缓存必须作为服务可用。您可以使用服务管理器等注册自己的缓存服务。对于这些自定义缓存,您不能使用--list
和--status --all
命令,并且您需要提供缓存的服务名称。
使用方法
输入php public/index.php
将显示您应用程序中所有可用的命令,包括所有Soflomo\Cache命令。
列出所有可用缓存
php public/index.php cache --list
注意。您必须使用抽象工厂定义您的缓存。
获取缓存状态
php public/index.php cache --status
如果您只有一个缓存定义,则选择此缓存。对于多个缓存,您将能够选择要打印状态的缓存。
当您的缓存未使用抽象工厂定义时,您必须提供缓存名称
php public/index.php cache --status MyCacheServiceName
所有缓存状态都使用--all
列出
php public/index.php cache --status --all
注意,使用--all
仅列出抽象工厂中的缓存。
清除缓存
php public/index.php cache --flush
如果您只有一个缓存定义,则选择此缓存。对于多个缓存,您将能够选择要打印状态的缓存。
当您的缓存未使用抽象工厂定义时,您必须提供缓存名称
php public/index.php cache --flush MyCacheServiceName
所有清除操作,包括--flush
,都需要通过提示进行确认。在不交互式使用命令时,您可以使用--force
或-f
标志
php public/index.php cache --flush --force
清除所有过期项
php public/index.php cache --clear --expired
如果您只有一个缓存定义,则选择此缓存。对于多个缓存,您将能够选择要打印状态的缓存。
当您的缓存未使用抽象工厂定义时,您必须提供缓存名称
php public/index.php cache --clear MyCacheServiceName --expired
所有清除操作,包括--clear --expired
,都需要通过提示进行确认。在不交互式使用命令时,您可以使用--force
或-f
标志
php public/index.php cache --clear --expired --force
通过命名空间清除项目
php public/index.php cache --clear --by-namespace=MyNamespace
如果您只有一个缓存定义,则选择此缓存。对于多个缓存,您将能够选择要打印状态的缓存。
当您的缓存未使用抽象工厂定义时,您必须提供缓存名称
php public/index.php cache --clear MyCacheServiceName --by-namespace=MyNamespace
所有清除操作,包括--clear --by-namespace=MyNamespace
,都需要通过提示进行确认。在不交互式使用命令时,您可以使用--force
或-f
标志
php public/index.php cache --clear --force --by-namespace=MyNamespace
通过前缀清除项目
php public/index.php cache --clear --by-prefix=MyPrefix
如果您只有一个缓存定义,则选择此缓存。对于多个缓存,您将能够选择要打印状态的缓存。
当您的缓存未使用抽象工厂定义时,您必须提供缓存名称
php public/index.php cache --clear MyCacheServiceName --by-prefix=MyPrefix
所有清除操作,包括--clear --by-prefix=MyPrefix
,都需要通过提示进行确认。若以非交互式方式使用命令,可以使用--force
或-f
标志。
php public/index.php cache --clear --force --by-prefix=MyPrefix
清除 ZF2 应用程序的配置缓存
php public/index.php cache --clear-config
清除 ZF2 应用程序的模块映射
php public/index.php cache --module-map
清除操作码缓存
目前,无法清除操作码缓存。CLI 和 PHP-FPM 的操作码缓存不共享,因此您无法使用 CLI 控制来自 PHP-FPM 的缓存。
类似于 Symfony 的 ApcBundle,需要在网站目录中创建一个文件,并通过 HTTP 调用该文件。然后该文件可以清除 PHP-FPM 的操作码缓存。您可以在 issue #2 中跟踪此功能的进展。