Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default cache backend #124

Closed
colinmollenhour opened this issue Nov 9, 2012 · 14 comments
Closed

Change default cache backend #124

colinmollenhour opened this issue Nov 9, 2012 · 14 comments

Comments

@colinmollenhour
Copy link

Of course advanced users can do some research and choose a backend that best suits their needs, but the default backend (Zend_Cache_Backend_File) is widely used simply because it is the default despite it having terrible performance with cleaning tags. For example there are several forum threads where users recommend shop owners to clear their cache periodically to maintain good performance. Clearing cache should not be necessary to maintain good performance for a small store. Also, if there is a better solution with no drawbacks, why not use it?

I recommend changing the default to Cm_Cache_Backend_File which has the same basic requirements (write access to var/cache) but does not rape the file system when clearing cache entries by tag. It does perform one append-only write for each tag when a cache item is saved, but overall utilizes the disk much more conservatively (way fewer inodes, way fewer file reads). I'm not sure what your requirements are for bundling third-party code, but here it is if interested: https://github.com/colinmollenhour/Cm_Cache_Backend_File

I will add a license to it if you like, let me know if you have a preference.

Summary from my Imagine 2012 presentation:
Basic Comparison

@JosephMaxwell
Copy link
Contributor

Excellent extension! It would be fantastic to have this included.

@magento-team
Copy link
Contributor

Hello. We are actively researching solutions for that and definitely Redis is under consideration.

@colinmollenhour
Copy link
Author

Although I think Redis makes an excellent backend for just about any size deployment I wasn't suggesting Redis as the default since it obviously adds a Redis server as a dependency. I was only suggesting that my file-based backend be bundled and used as the default since it doesn't degrade over time and is more efficient to boot.

@magento-team
Copy link
Contributor

Hello Collin, thanks for the suggestion. It definitely makes sense and I will put in the backlog. As for the license we can take MIT, Apache, BSD.

@colinmollenhour
Copy link
Author

Oh, looks like I already had it licensed under BSD after-all..

@akira28
Copy link

akira28 commented Nov 14, 2012

An optional Redis cache would be fantastic! But I agree with Colin, a file based one is necessary for people that doesn't have access to dedicated servers

@blitux
Copy link

blitux commented Dec 4, 2012

There's a Drupal cache module called Boost that generates html pages accesible via special htaccess rules (generated by the module itself), so the content is being served directly by the web server bypassing php/database. It's just another idea for a cache system.

@mshmsh5000
Copy link

Also brilliant, from the same developer, is the more abstract Expire module, which tracks the association of items within collections, so that a change to that item prompts cache invalidation in every page where it appears.

@magento-team
Copy link
Contributor

Hello. File backend (based on Colin's code) will become default once we merge a set of important changes from 1.x series. Redis backend will be default for multi-server installations replacing two-level memcache + DB setup. This merge is expected to happen after Q1 '13.

@ihor-sviziev
Copy link
Contributor

@mage2-team what's about redis?

@kandy
Copy link
Contributor

kandy commented Apr 8, 2014

@igor-svizev lib/Cm/Cache/Backend/Redis.php?

@ihor-sviziev
Copy link
Contributor

@kandy could you describe for me, what I should change to start use it?

@kandy
Copy link
Contributor

kandy commented Apr 8, 2014

I don't try do it by self
Maybe Configuring Caching documentation will help

@ihor-sviziev
Copy link
Contributor

@kandy thanks,
Finally works with next configuration in local.xml:

<?xml version="1.0"?>
<config>
    ...
    <cache>
        <frontend name="default">
            <backend>Cm_Cache_Backend_Redis</backend>
            <backend_options><server>127.0.0.1</server> <!-- or absolute path to unix socket -->
                <port>6379</port>
                <persistent></persistent> <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 -->
                <database>0</database> <!-- Redis database number; protection against accidental data loss is improved by not sharing databases -->
                <password></password> <!-- Specify if your Redis server requires authentication -->
                <force_standalone>0</force_standalone>  <!-- 0 for phpredis, 1 for standalone PHP -->
                <connect_retries>1</connect_retries>    <!-- Reduces errors due to random connection failures; a value of 1 will not retry after the first failure -->
                <read_timeout>10</read_timeout>         <!-- Set read timeout duration; phpredis does not currently support setting read timeouts -->
                <automatic_cleaning_factor>0</automatic_cleaning_factor> <!-- Disabled by default -->
                <compress_data>1</compress_data>  <!-- 0-9 for compression level, recommended: 0 or 1 -->
                <compress_tags>1</compress_tags>  <!-- 0-9 for compression level, recommended: 0 or 1 -->
                <compress_threshold>20480</compress_threshold>  <!-- Strings below this size will not be compressed -->
                <compression_lib>lzf</compression_lib> <!-- Supports gzip, lzf, lz4 (as l4z) and snappy -->
                <use_lua>0</use_lua> <!-- Set to 1 if Lua scripts should be used for some operations -->
            </backend_options>
        </frontend>
        <frontend name="page_cache">
            <backend>Cm_Cache_Backend_Redis</backend>
            <backend_options>
                <server>127.0.0.1</server> <!-- or absolute path to unix socket -->
                <port>6379</port>
                <persistent></persistent> <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 -->
                <database>1</database> <!-- Redis database number; protection against accidental data loss is improved by not sharing databases -->
                <password></password> <!-- Specify if your Redis server requires authentication -->
                <force_standalone>0</force_standalone>  <!-- 0 for phpredis, 1 for standalone PHP -->
                <connect_retries>1</connect_retries>    <!-- Reduces errors due to random connection failures -->
                <lifetimelimit>57600</lifetimelimit>    <!-- 16 hours of lifetime for cache record -->
                <compress_data>0</compress_data>        <!-- DISABLE compression for EE FPC since it already uses compression -->
            </backend_options>
        </frontend>
    </cache>
    ...
</config>

PS: In that folder we also have Cm_Cache_Backend_File, what's different between this class & standard Magento cache in files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants