Magento2 | Store cache into Database | Cache Management for Beginner | Part3

Store Cache into Database Instead of File system : Default magento system will store the cache into File system. Magento is providing us, one more option to store the cache into Database instead of cache & page_cache folder. Using this mechanism, the cache object/data will be storing into following 2 tables in magento.

  • cache
  • cache_tag

How to configure Database Cache setup in Magento2 : There are 2 options are available to do the Database Cache setup in Magento2,

  1. Default Cache frontend (di.xml file change)
  2. Custom Cache frontend (env.php file change)

Option 1: Database caching using the default cache frontend

  1. Edit app/etc/di.xml file (It’s global di configuration file in magento2) & check file permission
  2. Find below code snippet,
  3. Replace above code with following code snippet
  4. Clear var/cache & var/page_cache folder
  5. Reload any cache page more than 1 time.
  6. Verify var/cache & var/page_cache folder should be clean but “cache” & “cache_tag” should have the records/rows.

Note:  Before do the step:3, cross verify with app/etc/env.php cache should be frontend “cache ID” is “default” or not. If default than follow rest of the steps. Refer below screen

Option 2: Database caching using custom cache frontend :

  1. Edit app/etc/env.php & check file permission
  2. add below code snippet,
  3. Clear var/cache , var/page_cache, generated/code/, generated/metadata/ folder & check the cache & cache_tag table.

Note:

Due to a known issue, a custom cache frontend (ex: magento_cache) still results in some objects being cached to the file system, however, fewer assets are cached compared to file system caching. If you are using default cache frontend you don’t have face any issues.

Cons:

  • Database cache is well and good only on development environment.
  • On production mode this option is not a suggested one.
  • Many DB request will hit the Database server when we enable this cache.
  • Database used memory/size keep on will increase

Use Water but NEVER Waste WATER!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s