Skip to content

Commit

Permalink
First version, works for product detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenvermeulen committed Aug 23, 2014
0 parents commit 1a5ef0c
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*~
/.idea/
/var/connect/package.xml
62 changes: 62 additions & 0 deletions app/code/community/JeroenVermeulen/BlockCache/Model/Observer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

class JeroenVermeulen_BlockCache_Model_Observer extends Mage_Core_Model_Abstract
{

/**
* @param Varien_Event_Observer $observer
*/
function coreBlockAbstractToHtmlBefore( $observer )
{
$block = $observer->getBlock();
if ( is_a($block,'Mage_Catalog_Block_Product_Abstract') ) { // @TODO make enable/disable configurable

$cacheTags = array( Mage_Core_Model_Store::CACHE_TAG,
Mage_Catalog_Model_Category::CACHE_TAG,
Mage_Catalog_Model_Product::CACHE_TAG,
'BLOCK_HTML' );
$currentCategory = Mage::registry('current_category');
if ( $currentCategory ) {
$cacheTags[] = Mage_Catalog_Model_Category::CACHE_TAG.$currentCategory->getId(); // found in Mage_Catalog_Model_Layer
$cacheTags[] = Mage_Catalog_Model_Category::CACHE_TAG.'_'.$currentCategory->getId(); // found in Mage_Catalog_Model_Product
}
$currentProduct = Mage::registry('current_product');
if ( $currentProduct ) {
$cacheTags[] = Mage_Catalog_Model_Product::CACHE_TAG.'_'.$currentProduct->getId();
}

$cacheKeyData = array(
get_class( $block ),
Mage::helper('core/url')->getCurrentUrl(), // includes secure, storecode
Mage::getSingleton('customer/session')->getCustomerGroupId(),
$block->getTemplate(),
);

$block->setCacheKey( implode('_', $cacheKeyData) );
$block->setCacheTags( $cacheTags );
$block->setCacheLifetime( 3600 ); // 1 hour @TODO make configurable
}
/* TODO if category block:
{
$cacheTags = array( Mage_Core_Model_Store::CACHE_TAG,
Mage_Catalog_Model_Category::CACHE_TAG,
'BLOCK_HTML' );
$currentCategory = Mage::registry('current_category');
if ( $currentCategory ) {
$cacheTags[] = Mage_Catalog_Model_Category::CACHE_TAG.$currentCategory->getId();
}
$cacheKeyData = array( get_class( $block ),
Mage::app()->getStore()->getId(),
$this->helper('core/url')->getCurrentUrl(),
Mage::getSingleton('customer/session')->getCustomerGroupId(),
$this->getTemplate() );
$block->setCacheKey( implode('_', $cacheKeyData) );
$this->setCacheTags( $cacheTags );
$this->setCacheLifetime( 604800 ); // 1 week
}
*/
}

}
28 changes: 28 additions & 0 deletions app/code/community/JeroenVermeulen/BlockCache/etc/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<config>
<modules>
<jeroenvermeulen_blockcache>
<version>0.2.0</version>
</jeroenvermeulen_blockcache>
</modules>
<global>
<models>
<jeroenvermeulen_blockcache>
<class>JeroenVermeulen_BlockCache_Model</class>
</jeroenvermeulen_blockcache>
</models>
</global>
<frontend>
<events>
<core_block_abstract_to_html_before>
<observers>
<jeroenvermeulen_blockcache>
<type>singleton</type>
<class>JeroenVermeulen_BlockCache_Model_Observer</class>
<method>coreBlockAbstractToHtmlBefore</method>
</jeroenvermeulen_blockcache>
</observers>
</core_block_abstract_to_html_before>
</events>
</frontend>
</config>
12 changes: 12 additions & 0 deletions app/etc/modules/JeroenVermeulen_BlockCache.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<config>
<modules>
<JeroenVermeulen_BlockCache>
<active>true</active>
<codePool>community</codePool>
<depends>
<Mage_Catalog/>
</depends>
</JeroenVermeulen_BlockCache>
</modules>
</config>
9 changes: 9 additions & 0 deletions modman
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## JeroenVermeulen_BlockCache Extension - Performance Improvement by better block caching in Magento CE

# ---- Module enable XML
# Magento Global Config - File - modules/JeroenVermeulen_BlockCache.xml
app/etc/modules/JeroenVermeulen_BlockCache.xml app/etc/modules/JeroenVermeulen_BlockCache.xml

# ---- Extension code dir
# Magento Community Module - Recursive Dir - JeroenVermeulen/BlockCache
app/code/community/JeroenVermeulen/BlockCache/ app/code/community/JeroenVermeulen/BlockCache/

0 comments on commit 1a5ef0c

Please sign in to comment.