Friday 10 April 2009

Working on the cache

The config and cache are probably the two worst offenders in magento.

The cache can actually slow down your site because ZF doesn't keep an index of tags on your cached data. If you specify that you want to clean up all "shopping cart" tagged data, ZF cache has to search every single metadata file and look for the tag... resulting in hundreds or thousands of fopen, fread, fclose calls on your system.

If you try to use one of the memory cache backends, like memcache or APC you'll find that they perform *worse* than the file cache. Magento's concept of caching is throwing thousands of tiny little objects into individual files creates huge fragmentation in the memory and actually slows the site down.

The entire way the cache works needs to be thrown out and started over. It should be federated into different directories for config data, template data and all the other top level cache controls currently available. I'm kind of scared to load two or more instances of Zend_Cache_Core in one request. Savvy ZF people will say, "Oh, but it has a nesting depth setting.", not what I'm talking about. The next thing that needs to change: only large chunks of data need to be stored in a cache. Tiny pieces of template data which take little time to compute should not be kept in the cache. Entire pages, on the other hand, could be saved in the cache, minus the customer cart side bar and login/logout links.

No comments: