Moshe, when you have a minute, could you please give us some details on how the cache system works in Magento ?
For a category/product/home page, which parts of the page are actually cached ?
Let’s assume I have activated the cache for all the settings in the cache control admin, how much does the cache actually improve the load time for a specific page, considering this page has already been loaded previously ? Can we expect zero SQL queries to be executed for the page (apart from the visitor logging queries) ?
I have checked the var/cache directory on my setup and found just a few files, even if my catalog is quite big (thousands active products), and did get visits on hundreds of products after a cache refresh, how comes I don’t get more cached items ?
Hi, currently the caching is implemented in core components mostly.
* Configuration
Here we cache merged config.xml files from app/etc/, all the modules and custom configuration saved in the database.
* Layouts
Compiling layout updates from app/design/[package]/[theme]/layout/*.xml files into layouts cache for each page
* Blocks HTML output
Every block can be cacheable by setting cache_lifetime and cache_key.
This could involve pretty sophisticated logic to avoid representation inconsistencies between different blocks.
Currently only admin top navigation block is cached.
* EAV types and attributes
EAV (entity-attribute-value model) requires configuration to be loaded from database. To speed up the initialization we cache this configuration.
* Translations
Every module and every theme can supply it’s own translation files (currently .csv) We cache all of them to avoid wasting time on recompilation.
You could play with setCacheLifetime and setCacheKey for blocks that display product data and see how it works for you
@perteweb—does this also refresh the Catalog Rewrites, Images Cache, and Layered Nav Indices (i.e., everything in the lower box on the /system_cache/ admin page)? If not, any idea how to clean those out with either a cron or line of code?
I did. Someone from Varien please correct me if I’m wrong, but I think you can run this as a cron—just comment out the parts you don’t want to clear out:
// you need this in a file to start up Magento $mageFilename = '/{{YOUR PATH TO MAGENTO}}/app/Mage.php'; require_once $mageFilename; umask(0); Mage::run();
// clean overall cache Mage::app()->cleanCache();
// clear 'refresh_catalog_rewrites': Mage::getSingleton('catalog/url')->refreshRewrites(); echo 'Catalog Rewrites was refreshed succesfuly<br>';
// clear 'clear_images_cache': Mage::getModel('catalog/product_image')->clearCache(); echo 'Image cache was cleared succesfuly<br>';
// clear 'refresh_layered_navigation': Mage::getSingleton('catalogindex/indexer')->plainReindex(); echo 'Layered Navigation Indices was refreshed succesfuly<br>';
The XXX is my hosting username that I just removed in my reply. I tried to use your code, but it is not working. As I mentioned, I’m getting the above error message.
And inside that php script you add the command to clean the cache. Remember this script should include the magento core files. Take a look at magento’s /index.php, it will be something like that whithout the last line, Mage::run(); and some other unnecessary code.
Also, I suppose the correct code is:
Mage::app()->getCache()->clean();
since ‘clean’ is a method. I haven’t tested it, though.
Mage::getSingleton('catalog/url')->refreshRewrites(); Mage::getModel('catalog/product_image')->clearCache(); Mage::getSingleton('catalogindex/indexer')->plainReindex(); or