如何用命令行刷新/启用/禁用Magento2的缓存

4.00K 浏览M2安装设置

如何用命令行刷新/启用/禁用Magento2的缓存

image http://bbs.mallol.cn/assets/images/1-iEd6EbzCdqki0f1s.jpeg

在很多人眼里,magento慢如蜗牛,但是magento的缓存很强大,用好缓存 可以享受飞一般的感觉。
如何清理Magento 2中的Cache?是我们使用Magento时经常用到的。
Magento 2默认有12种缓存类型。在命令行中有5个简单的命令来管理缓存。

image http://bbs.mallol.cn/assets/images/1-sWiIFQGgVdUyXd6D.jpeg

刷新Magento 2缓存:

  • 转到Magento根目录
  • php bin/magento cache:clean'和php bin/magento cache:flush`
  • 好了 去你的Magento商店,检查结果。

在Ubuntu,Centos或Windows中更改当前目录
Ubuntu的: cd /var/www/magento2
CentOS的: cd /var/www/html/magento2
Windows: cd /d/xampp/htdocs/magento2 (windows一般安装xampp)
在Magento 2中,让我们尝试执行命令行php bin/magento,它将显示如下:

<code>Magento CLI version 2 Usage: command [options] [arguments] Options: --help (-h) Display this help message --quiet (-q) Do not output any message --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --version (-V) Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output --no-interaction (-n) Do not ask any interactive question Available commands: help Displays help for a command list Lists commands admin admin:user:create Creates an administrator admin:user:unlock Unlock Admin Account cache cache:clean Cleans cache type(s) cache:disable Disables cache type(s) cache:enable Enables cache type(s) cache:flush Flushes cache storage used by cache type(s)</code>

在本指南中,我将Cache在命令行中详细讨论管理。

检查缓存状态

首先,通过以下命令行来显示缓存状态:

<code>php bin/magento cache:status</code>

缓存状态的结果

<code>Current status: config: 1 layout: 1 block_html: 1 collections: 1 reflection: 1 db_ddl: 1 eav: 1 config_integration: 1 config_integration_api: 1 full_page: 1 translate: 1 config_webservice: 1</code>

清理缓存命令行

php bin/magento cache:clean

清除缓存类型使用的缓存存储 命令行

缓存存储可能包含其他数据,如服务器缓存。
php bin/magento cache:flush

禁用缓存命令行

以下命令将禁用所有缓存类型
php bin/magento cache:disable
如果你想禁用特定的缓存类型,你应该输入命令行
php bin/magento cache:disable CACHE_TYPE
例:
php bin/magento cache:disable config

启用缓存命令行

这与如何禁用缓存所有类型和特定缓存类型类似

启用所有缓存类型
php bin/magento cache:enable
启用特定的缓存类型
php bin/magento cache:enable CACHE_TYPE

php bin/magento cache:enable layout

0