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.
How to configure Database Cache setup in Magento2 : There are 2 options are available to do the Database Cache setup in Magento2,
- Default Cache frontend (di.xml file change)
- Custom Cache frontend (env.php file change)
Option 1: Database caching using the default cache frontend
- Edit app/etc/di.xml file (It’s global di configuration file in magento2) & check file permission
- Find below code snippet,
- Replace above code with following code snippet
- Clear var/cache & var/page_cache folder
- Reload any cache page more than 1 time.
- 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 :
- Edit app/etc/env.php & check file permission
- add below code snippet,
- 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.
- 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