3

I am using memcache.

I want to understand what is stored in Magento cache and how?

Do magento stores cache variable with website scope or store scope?

I have googled and greped the code but couldnt conclude anything,

Please if someone can direct me to correct links and path

Thanks & Regards, Saurabh

1
  • What version? Of magento Commented Dec 21, 2014 at 12:45

4 Answers 4

14

If you go to the Cache Management section of the admin area you can see what it caches (configuration, layout configuration, block html output, translations, eav types, etc). I am no expert on Magento's caching mechanisms but here are a few random tidbits that might be helpful (maybe). (Also note that I am only familiar with Magento 1.3.x, not 1.4.x so things could have changed).

The caching is actually stored in the var/cache directory. There are a ton of directories in there (mage--0, mage--1, mage--2) and each directory has the cache files. Do a ls var/cache/mage*/* to see all the files.

Configuration - This source for the configuration is varied. Your app/etc/local.xml, and all of the config.xml files (that are in each module's etc dir) are combined together to make one big configuration object. Then Magento reads from the core_config_data table to update the configuration object. Then the configuration is written to a cache file so that next time a request is made it doesn't need to open a ton of config files and hit the database. Somehow this info gets stored in a bunch of files under var/cache. For some insight do a ls var/cache/mage*/*CONF*.

Layout - This is a lot like the configuration... there are a bunch of xml files in the app/design/frontendOrAdminhtml/yournamespace/layout/ directory and all these are merged into one layout configuration object, then cached in the cache directory.

Block HTML - The actual html generated by a block is cached. Each block is able to decide how long it is going to be cached.

Lastly, to (not really) answer your question about if the cache is per website or store, I can't really say since I haven't had the need to setup a multi-website/multi-store shop yet. It looks like there may be some store/website-specific files, but I can't see that they are really organized in a logical way. For example, in one of my instances I see a var/cache/mage--f/mage---LAYOUT_FRONTEND_STORE0_DEFAULT_BLANK_SEO file and a var/cache/mage--f/mage---LAYOUT_FRONTEND_STORE1_DEFAULT_BLANK_SEO... but then again, I only have one store configured and those two files have the same contents. Good luck with that!

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Sdek, Thank you for detailed explanation. As I was trying to figure out this I found that there is cache key generated for the blocks which are cached. One of it looks like "Cache Key: CATALOG_PRODUCT_NEW_1_default_a022_1_d6cc4b5d3cce3f79f5254e4a971267f5_20" Now I am looking for how this is formed I think '1' after a022 is website id. Note: a022 is my theme.
You state that the cache files are stored in var/cache. If he is using Memcached they shouldn't be stored there, unless it needs some files there.
Yeah, that is what I thought too, but I think it stores the cache on both the file system and in memcached. I was perplexed about that as well. Been over a year since I looked at this so I could be mistaken.
1

You could also use some of the very great memcached analysis and reporting tools available

http://code.google.com/p/memcached/wiki/Tools

Comments

1

The best solution I have come up with is to use a two level cache. Consult app/etc/local.xml.additional to see how to put memcached server nodes in there. Note that within the <servers> tag you will have to have tags like <server1> and <server2> encapsulating each memcached node's settings.

<cache>
    <backend>memcached</backend>
    <slow_backend>database</slow_backend>
</cache>

In this way all cache is shared.

To clear it the way I do it is to:
1. shut down apache
2. connect to mysql and connect to the magento db and run truncate core_cache; truncate core_cache_tag.
3. I then bounce the memcached nodes.
4. I restart apache but I keep it out of the load balancer until I have hit it at least once to generate the APC opcode cache. Otherwise the load can shot up through the roof.

This all seems extreme but I have found it works for me. Clearing cache using the backend is REALLY slow. I have around 100k entries in the core_cache table and close to 1 million entries in core_cache_tag. If I don't do it this way sometimes I get strange behavior.

4 Comments

Can you please describe what you mean with "I then bounce the memcached nodes." And why do you need to shut down apache. I have truncated the core_cache_tag without stopping apache. And for step 4. can you explain how you keep apache of the load balancer?
@nicoX - My comment at this point is pretty antiquated. By "bounce" I mean restart memcached so all cache is cleared. My current advice would be to use Redis instead: github.com/colinmollenhour/Cm_Cache_Backend_Redis
We are running memcached live now and are not in the position to go over to Redis at the moment. I restarted memcached, checked the var/cache directory and there where still cached files as previous
@nicoX - Are you using database as your 2nd level or filesystem? How many apache nodes are you using? Regarding my comment about keeping apache out of the load balancer there is a healthcheck file which I would temporarily rename. Then I could hit that node directly via it's external ip address to warm the APC opcode cache. And please look into redis ASAP. It makes all this much much simpler as well as more performant.
1

Your Memcache configuration in ./app/etc/local/xml will dictate what Memcache is actually caching.

If you are only using a the single-level cache (without ), then Magento will store its cache (in its entirety) in Memcache.

HOWEVER without the slow_backend defined - it is caching content, without cache_tags - ie. without the ability to differentiate cache items

Eg. configuration, block, layouts, translations etc.

So, without the defined, you cannot refresh caches individually, in-fact, you'll almost always have to rely on "Flush Cache Storage" to actually see updates take effect.

We wrote a nice article here which covers your very issue - http://www.sonassi.com/knowledge-base/magento-knowledge-base/what-is-memcache-actually-caching-in-magento/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.