-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version, works for product detail page
- Loading branch information
0 parents
commit 1a5ef0c
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
62
app/code/community/JeroenVermeulen/BlockCache/Model/Observer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
app/code/community/JeroenVermeulen/BlockCache/etc/config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |