Installation and configuration of the Magento Mage_Cache_Backend_File in versions prior EE1.13 / CE 1.8

The Latest Magento releases (community edition 1.8 apha and enterprise 1.13) come with a new cache backend, Mage_Cache_Backend_File.

This backend reduces inode usage when saving the cached content.

You are on a prior version but want to use it? No problem, but there are few things to fix before

Mage_Cache_Backend_File backend source code installation

1. Getting Mage_Cache_Backend_File source code

If you do not have access to the Magento enterprise source code, don’t worry: you can also retrieve the backend source code from the Magento community 1.8 aplha version: the file content is the same

File is located in lib/Mage/Cache/Backend/File.php

2. Install Mage_Cache_Backend_File

Depending on if you want to be able to overload it, there are two possible locations where to put this file:

  • app/code/local/Mage/Cache/Backend/File.php:

    the access to this file will be faster than if it is located in commmunity folder (autoloader will check this folder first).

    But you won’t be able to overload it

  • app/code/community/Mage/Cache/Backend/File.php: in this case, you keep the possibility to overload the backend

We have excluded the two other source code folders for the following reasons:

  • lib: In this case you realize a partial upgrade, and we do not want to merge lib folder content
  • app/code/core must not be updated

Mage_Cache_Backend_File configuration usage

How to notify Magento the Mage_Cache_Backend_File backend usage?

There is nothing difficult to specify this cache backend for cache usage: we use the native functionnality that allows using any class as cache engine, as this class extends Zend_Cache_Backend. Depending on your cache usage, you’ll have to update your cache configuration according to the following examples

No memory usage, no full page cache, only Mage_Cache_Backend_File

<config>
<global>
<cache>
<backend>Mage_Cache_Backend_File</backend>
</cache>
</global>
</config>

A backend memory, no full page cache, Mage_Cache_Backend_File as slow backend

<config>
<global>
<cache>
<slow_backend>Mage_Cache_Backend_File</slow_backend>
</cache>
</global>
</config>

Mage_Cache_Backend_File as slow backend for full page cache only

<config>
<global>
<full_page_cache>
<slow_backend>Mage_Cache_Backend_File</slow_backend>
</full_page_cache>
</config>
</global>

Mage_Cache_Backend_File as slow backend for cache and full page cache

<config>
<global>
<cache>
<slow_backend>Mage_Cache_Backend_File</slow_backend>
</cache>
<full_page_cache>
<slow_backend>Mage_Cache_Backend_File</slow_backend>
</full_page_cache>
</config>
</global>

Mage_Cache_Backend_File cache configuration for backward compatibility

Problem is when you set up the configuration above, your cache folder (by default var/cache) will remain empty; where is stored the cache content now? In system tmp folder

I don’t know exactly (and I’ve not looked for yet) where is the origin of the problem. But if you want to keep backward compatibility with used cache folder, you have to force it with the cache_dir configuration option

Mage_Cache_Backend_File for every file cache engine

That’s it, nothing more: we need only few steps to use this backend. You can now benefit from the less inode usage

Note that when you install Magento EE1.13, Mage_Cache_Backend_File is defined as cache backend only for the full page cache. I’ve tested it on further Magento projects (CE1.6, EE1.11, EE1.10.1) for cache and full page cache management during a few weeks without any problems. If you have any details why Magento made this choice, I’m interested