當你使用Magento商店時如何刷新Magento 2中的Cache命令行是基本的常用操作。Magento 2默認有12種緩存類型。在命令行中有5個簡單的命令來管理緩存。在這篇文章中,我將逐步向您展示每個命令行。
我將在這個截圖中解釋緩存管理
刷新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在D驅動器。
在Magento 2中,讓我們嘗試使用php bin/magento
顯示命令行指南,它將顯示如下:
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)
在本指南中,我將詳細討論Cache
命令行管理。
檢查緩存狀態
首先,通過以下命令行來顯示緩存狀態:
- php bin/magento cache:status
緩存狀態的結果
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
清理緩存命令行
- 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