Version Notes
N/A
Download this release
Release Info
| Developer | Jonathan Selander |
| Extension | Made_Cache |
| Version | 1.0.3 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0.1 to 1.0.3
- app/code/community/Made/Cache/Block/Catalog/Product/View.php +22 -2
- app/code/community/Made/Cache/Block/Cms/Block.php +64 -0
- app/code/community/Made/Cache/Block/Cms/Page.php +53 -0
- app/code/community/Made/Cache/Block/Cms/Widget/Block.php +61 -0
- app/code/community/Made/Cache/Model/Layout.php +18 -3
- app/code/community/Made/Cache/etc/config.xml +8 -1
- package.xml +4 -4
app/code/community/Made/Cache/Block/Catalog/Product/View.php
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
<?php
|
| 2 |
/**
|
| 3 |
-
* Granular product view cache
|
|
|
|
|
|
|
| 4 |
*
|
| 5 |
* @package Made_Cache
|
| 6 |
* @author info@madepeople.se
|
|
@@ -8,6 +10,23 @@
|
|
| 8 |
*/
|
| 9 |
class Made_Cache_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
|
| 10 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
/**
|
| 12 |
* Only clear on the specific product id - otherwise one product save
|
| 13 |
* invalidates cache for all products
|
|
@@ -17,7 +36,8 @@ class Made_Cache_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_V
|
|
| 17 |
public function getCacheTags()
|
| 18 |
{
|
| 19 |
$tags = parent::getCacheTags();
|
| 20 |
-
$tags[] = Mage_Catalog_Model_Product::CACHE_TAG . '_'
|
|
|
|
| 21 |
return $tags;
|
| 22 |
}
|
| 23 |
|
| 1 |
<?php
|
| 2 |
/**
|
| 3 |
+
* Granular product view cache. Currently the product object is fetched
|
| 4 |
+
* in the controller/helper regardless of existing cache or not. As this
|
| 5 |
+
* is a block-level cache module, we choose to ignore that.
|
| 6 |
*
|
| 7 |
* @package Made_Cache
|
| 8 |
* @author info@madepeople.se
|
| 10 |
*/
|
| 11 |
class Made_Cache_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
|
| 12 |
{
|
| 13 |
+
/**
|
| 14 |
+
* We don't want to cache an item that's being edited
|
| 15 |
+
*
|
| 16 |
+
* @return null|int
|
| 17 |
+
*/
|
| 18 |
+
public function getCacheLifetime()
|
| 19 |
+
{
|
| 20 |
+
$request = $this->getRequest();
|
| 21 |
+
if ($request->getModuleName() == 'checkout'
|
| 22 |
+
&& $request->getControllerName() == 'cart'
|
| 23 |
+
&& $request->getActionName() == 'configure'
|
| 24 |
+
&& $request->getParam('id')) {
|
| 25 |
+
return null;
|
| 26 |
+
}
|
| 27 |
+
return $this->getData('cache_lifetime');
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
/**
|
| 31 |
* Only clear on the specific product id - otherwise one product save
|
| 32 |
* invalidates cache for all products
|
| 36 |
public function getCacheTags()
|
| 37 |
{
|
| 38 |
$tags = parent::getCacheTags();
|
| 39 |
+
$tags[] = Mage_Catalog_Model_Product::CACHE_TAG . '_'
|
| 40 |
+
. $this->getProduct()->getId();
|
| 41 |
return $tags;
|
| 42 |
}
|
| 43 |
|
app/code/community/Made/Cache/Block/Cms/Block.php
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Cache the CMS block, the issue here is that it doesn't necessarily exist
|
| 4 |
+
* so we must take this into concern and not cache if there is nothing
|
| 5 |
+
* fetched from the database
|
| 6 |
+
*
|
| 7 |
+
* @package Made_Cache
|
| 8 |
+
* @author info@madepeople.se
|
| 9 |
+
* @copyright Copyright (c) 2012 Made People AB. (http://www.madepeople.se/)
|
| 10 |
+
*/
|
| 11 |
+
class Made_Cache_Block_Cms_Block extends Mage_Cms_Block_Block
|
| 12 |
+
{
|
| 13 |
+
/**
|
| 14 |
+
* Clear on the specific CMS block id
|
| 15 |
+
*
|
| 16 |
+
* @return string
|
| 17 |
+
*/
|
| 18 |
+
public function getCacheTags()
|
| 19 |
+
{
|
| 20 |
+
$blockId = $this->getData('block_id');
|
| 21 |
+
if ($blockId) {
|
| 22 |
+
$block = Mage::getModel('cms/block')
|
| 23 |
+
->setStoreId(Mage::app()->getStore()->getId())
|
| 24 |
+
->load($blockId);
|
| 25 |
+
if ($block->getIsActive()) {
|
| 26 |
+
$tags = parent::getCacheTags();
|
| 27 |
+
$tags[] = Mage_Cms_Model_Block::CACHE_TAG . '_' .
|
| 28 |
+
$block->getId();
|
| 29 |
+
|
| 30 |
+
return $tags;
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
return array();
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* Take into concern all variables that can affect the CMS block view
|
| 39 |
+
*
|
| 40 |
+
* @return array
|
| 41 |
+
*/
|
| 42 |
+
public function getCacheKeyInfo()
|
| 43 |
+
{
|
| 44 |
+
$blockId = $this->getData('block_id');
|
| 45 |
+
if ($blockId) {
|
| 46 |
+
$block = Mage::getModel('cms/block')
|
| 47 |
+
->setStoreId(Mage::app()->getStore()->getId())
|
| 48 |
+
->load($blockId);
|
| 49 |
+
if ($block->getIsActive()) {
|
| 50 |
+
$keys = parent::getCacheKeyInfo();
|
| 51 |
+
|
| 52 |
+
if (!is_array($keys)) {
|
| 53 |
+
$keys = array();
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
$keys[] = $blockId;
|
| 57 |
+
$keys[] = $this->getLayout()->getUpdate()->getCacheId();
|
| 58 |
+
return $keys;
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
return array();
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
}
|
app/code/community/Made/Cache/Block/Cms/Page.php
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Automatic CMS page cache
|
| 4 |
+
*
|
| 5 |
+
* @package Made_Cache
|
| 6 |
+
* @author info@madepeople.se
|
| 7 |
+
* @copyright Copyright (c) 2012 Made People AB. (http://www.madepeople.se/)
|
| 8 |
+
*/
|
| 9 |
+
class Made_Cache_Block_Cms_Page extends Mage_Cms_Block_Page
|
| 10 |
+
{
|
| 11 |
+
public function getCacheLifetime()
|
| 12 |
+
{
|
| 13 |
+
// If overriden by user
|
| 14 |
+
if ($this->hasData('cache_lifetime')) {
|
| 15 |
+
return $this->getData('lifetime');
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
return Made_Cache_Model_Layout::DEFAULT_CACHE_LIFETIME;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* Clear on the specific CMS page id
|
| 23 |
+
*
|
| 24 |
+
* @return string
|
| 25 |
+
*/
|
| 26 |
+
public function getCacheTags()
|
| 27 |
+
{
|
| 28 |
+
$tags = parent::getCacheTags();
|
| 29 |
+
$tags[] = Mage_Cms_Model_Page::CACHE_TAG . '_' .
|
| 30 |
+
$this->getPage()->getId();
|
| 31 |
+
|
| 32 |
+
return $tags;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Take into concern all variables that can affect the CMS page view
|
| 37 |
+
*
|
| 38 |
+
* @return array
|
| 39 |
+
*/
|
| 40 |
+
public function getCacheKeyInfo()
|
| 41 |
+
{
|
| 42 |
+
$keys = parent::getCacheKeyInfo();
|
| 43 |
+
|
| 44 |
+
if (!is_array($keys)) {
|
| 45 |
+
$keys = array();
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
$keys[] = $this->getPage()->getId();
|
| 49 |
+
$keys[] = $this->getLayout()->getUpdate()->getCacheId();
|
| 50 |
+
|
| 51 |
+
return $keys;
|
| 52 |
+
}
|
| 53 |
+
}
|
app/code/community/Made/Cache/Block/Cms/Widget/Block.php
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* As with the standard CMS block, for widget rendering
|
| 4 |
+
*
|
| 5 |
+
* @package Made_Cache
|
| 6 |
+
* @author info@madepeople.se
|
| 7 |
+
* @copyright Copyright (c) 2012 Made People AB. (http://www.madepeople.se/)
|
| 8 |
+
*/
|
| 9 |
+
class Made_Cache_Block_Cms_Widget_Block extends Mage_Cms_Block_Widget_Block
|
| 10 |
+
{
|
| 11 |
+
/**
|
| 12 |
+
* Clear on the specific CMS block id
|
| 13 |
+
*
|
| 14 |
+
* @return string
|
| 15 |
+
*/
|
| 16 |
+
public function getCacheTags()
|
| 17 |
+
{
|
| 18 |
+
$blockId = $this->getData('block_id');;
|
| 19 |
+
if ($blockId) {
|
| 20 |
+
$block = Mage::getModel('cms/block')
|
| 21 |
+
->setStoreId(Mage::app()->getStore()->getId())
|
| 22 |
+
->load($blockId);
|
| 23 |
+
if ($block->getIsActive()) {
|
| 24 |
+
$tags = parent::getCacheTags();
|
| 25 |
+
$tags[] = Mage_Cms_Model_Block::CACHE_TAG . '_' .
|
| 26 |
+
$block->getId();
|
| 27 |
+
|
| 28 |
+
return $tags;
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
return array();
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Take into concern all variables that can affect the CMS block view
|
| 37 |
+
*
|
| 38 |
+
* @return array
|
| 39 |
+
*/
|
| 40 |
+
public function getCacheKeyInfo()
|
| 41 |
+
{
|
| 42 |
+
$blockId = $this->getData('block_id');;
|
| 43 |
+
if ($blockId) {
|
| 44 |
+
$block = Mage::getModel('cms/block')
|
| 45 |
+
->setStoreId(Mage::app()->getStore()->getId())
|
| 46 |
+
->load($blockId);
|
| 47 |
+
if ($block->getIsActive()) {
|
| 48 |
+
$keys = parent::getCacheKeyInfo();
|
| 49 |
+
|
| 50 |
+
if (!is_array($keys)) {
|
| 51 |
+
$keys = array();
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
$keys[] = $blockId;
|
| 55 |
+
$keys[] = $this->getLayout()->getUpdate()->getCacheId();
|
| 56 |
+
return $keys;
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
return array();
|
| 60 |
+
}
|
| 61 |
+
}
|
app/code/community/Made/Cache/Model/Layout.php
CHANGED
|
@@ -21,7 +21,7 @@ class Made_Cache_Model_Layout extends Mage_Core_Model_Layout
|
|
| 21 |
*
|
| 22 |
* @var int
|
| 23 |
*/
|
| 24 |
-
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Aggregate <reference> tags into the final XML to be able to
|
|
@@ -65,7 +65,7 @@ class Made_Cache_Model_Layout extends Mage_Core_Model_Layout
|
|
| 65 |
foreach ($cacheList as $node) {
|
| 66 |
$lifetime = (int)$node->getAttribute('lifetime');
|
| 67 |
if (empty($lifetime)) {
|
| 68 |
-
$lifetime =
|
| 69 |
}
|
| 70 |
$this->_cacheBlocks[(string)$node] = $lifetime;
|
| 71 |
}
|
|
@@ -132,11 +132,26 @@ class Made_Cache_Model_Layout extends Mage_Core_Model_Layout
|
|
| 132 |
if (!empty($node['cache_key'])) {
|
| 133 |
$cacheKey = (string)$node['cache_tags'];
|
| 134 |
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
$_customer = Mage::getSingleton('customer/session')->getCustomer();
|
| 136 |
$cacheKey = (string)$node['name'] .
|
| 137 |
$this->getUpdate()->getCacheId() .
|
| 138 |
md5($_customer->getGroupId() .
|
| 139 |
-
join('_',
|
| 140 |
}
|
| 141 |
return $cacheKey;
|
| 142 |
}
|
| 21 |
*
|
| 22 |
* @var int
|
| 23 |
*/
|
| 24 |
+
const DEFAULT_CACHE_LIFETIME = 9999999999;
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Aggregate <reference> tags into the final XML to be able to
|
| 65 |
foreach ($cacheList as $node) {
|
| 66 |
$lifetime = (int)$node->getAttribute('lifetime');
|
| 67 |
if (empty($lifetime)) {
|
| 68 |
+
$lifetime = self::DEFAULT_CACHE_LIFETIME;
|
| 69 |
}
|
| 70 |
$this->_cacheBlocks[(string)$node] = $lifetime;
|
| 71 |
}
|
| 132 |
if (!empty($node['cache_key'])) {
|
| 133 |
$cacheKey = (string)$node['cache_tags'];
|
| 134 |
} else {
|
| 135 |
+
$paramKeys = array();
|
| 136 |
+
foreach (Mage::app()->getRequest()->getParams() as $key => $value) {
|
| 137 |
+
if (is_array($value)) {
|
| 138 |
+
$value = implode('_', $value);
|
| 139 |
+
} elseif (is_object($value)) {
|
| 140 |
+
$newValue = '';
|
| 141 |
+
foreach ($value->getData() as $dataKey => $dataValue) {
|
| 142 |
+
$newValue = $dataKey . $dataValue;
|
| 143 |
+
}
|
| 144 |
+
$value = $newValue;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
$paramKeys[] = $key . $value;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
$_customer = Mage::getSingleton('customer/session')->getCustomer();
|
| 151 |
$cacheKey = (string)$node['name'] .
|
| 152 |
$this->getUpdate()->getCacheId() .
|
| 153 |
md5($_customer->getGroupId() .
|
| 154 |
+
join('_', $paramKeys));
|
| 155 |
}
|
| 156 |
return $cacheKey;
|
| 157 |
}
|
app/code/community/Made/Cache/etc/config.xml
CHANGED
|
@@ -9,7 +9,7 @@
|
|
| 9 |
<config>
|
| 10 |
<modules>
|
| 11 |
<Made_Cache>
|
| 12 |
-
<version>1.0.
|
| 13 |
</Made_Cache>
|
| 14 |
</modules>
|
| 15 |
<global>
|
|
@@ -30,6 +30,13 @@
|
|
| 30 |
<product_list>Made_Cache_Block_Catalog_Product_List</product_list>
|
| 31 |
</rewrite>
|
| 32 |
</catalog>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
</blocks>
|
| 34 |
<events>
|
| 35 |
<review_save_after>
|
| 9 |
<config>
|
| 10 |
<modules>
|
| 11 |
<Made_Cache>
|
| 12 |
+
<version>1.0.3</version>
|
| 13 |
</Made_Cache>
|
| 14 |
</modules>
|
| 15 |
<global>
|
| 30 |
<product_list>Made_Cache_Block_Catalog_Product_List</product_list>
|
| 31 |
</rewrite>
|
| 32 |
</catalog>
|
| 33 |
+
<cms>
|
| 34 |
+
<rewrite>
|
| 35 |
+
<page>Made_Cache_Block_Cms_Page</page>
|
| 36 |
+
<block>Made_Cache_Block_Cms_Block</block>
|
| 37 |
+
<widget_block>Made_Cache_Block_Cms_Widget_Block</widget_block>
|
| 38 |
+
</rewrite>
|
| 39 |
+
</cms>
|
| 40 |
</blocks>
|
| 41 |
<events>
|
| 42 |
<review_save_after>
|
package.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Made_Cache</name>
|
| 4 |
-
<version>1.0.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license>OSL 3.0</license>
|
| 7 |
<channel>community</channel>
|
|
@@ -18,9 +18,9 @@ ESI is supported in conjunction with Phoenix_VarnishCache, and allows for super-
|
|
| 18 |
A good block cache is vital for scaling a site, be sure to implement it before residing to full page cache.</description>
|
| 19 |
<notes>N/A</notes>
|
| 20 |
<authors><author><name>Jonathan Selander</name><user>jonathan_monday</user><email>jonathan@mondaycreative.se</email></author></authors>
|
| 21 |
-
<date>2012-05-
|
| 22 |
-
<time>
|
| 23 |
-
<contents><target name="magecommunity"><dir name="Made"><dir name="Cache"><dir name="Block"><dir name="Catalog"><dir name="Product"><file name="List.php" hash="b6c67645954d1a8c2175b7d98fad68e4"/><file name="View.php" hash="
|
| 24 |
<compatible/>
|
| 25 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
| 26 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Made_Cache</name>
|
| 4 |
+
<version>1.0.3</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license>OSL 3.0</license>
|
| 7 |
<channel>community</channel>
|
| 18 |
A good block cache is vital for scaling a site, be sure to implement it before residing to full page cache.</description>
|
| 19 |
<notes>N/A</notes>
|
| 20 |
<authors><author><name>Jonathan Selander</name><user>jonathan_monday</user><email>jonathan@mondaycreative.se</email></author></authors>
|
| 21 |
+
<date>2012-05-09</date>
|
| 22 |
+
<time>11:59:26</time>
|
| 23 |
+
<contents><target name="magecommunity"><dir name="Made"><dir name="Cache"><dir name="Block"><dir name="Catalog"><dir name="Product"><file name="List.php" hash="b6c67645954d1a8c2175b7d98fad68e4"/><file name="View.php" hash="c6546846ffbcc0db89087670a7a496d6"/></dir></dir><dir name="Cms"><file name="Block.php" hash="e99bc96a3a6cd1bee4658b163b1ee63e"/><file name="Page.php" hash="156f4eb0d9dfd6f8dd0d3fce40f0c356"/><dir name="Widget"><file name="Block.php" hash="3e74a85404ab796bf46db6c36e479d49"/></dir></dir></dir><dir name="Model"><file name="Layout.php" hash="e85e4af8ebe74d2a9a5c5635373eed7d"/><file name="Observer.php" hash="6828f5e4b78dd32a52254d03faa0086f"/></dir><dir name="controllers"><file name="VarnishController.php" hash="6e7207e07c5385568061b853eeca96fd"/></dir><dir name="etc"><file name="config.xml" hash="c5432f1d8271a84aa6e1fe8bb83b064f"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Made_Cache.xml" hash="4cf53cc9b4e525eb560f7fe1278d96bd"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="madecache.xml" hash="3679ea4ed47b428e4c05314bf6bba3ee"/></dir></dir></dir></dir></target></contents>
|
| 24 |
<compatible/>
|
| 25 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
| 26 |
</package>
|
