Made_Cache - Version 1.0.4

Version Notes

N/A

Download this release

Release Info

Developer Jonathan Selander
Extension Made_Cache
Version 1.0.4
Comparing to
See all releases


Code changes from version 1.0.3 to 1.0.4

app/code/community/Made/Cache/Block/Catalog/Product/List.php CHANGED
@@ -32,7 +32,7 @@ class Made_Cache_Block_Catalog_Product_List extends Mage_Catalog_Block_Product_L
32
  */
33
  public function getCacheTags()
34
  {
35
- $tags = parent::getCacheTags();
36
  $tags[] = Mage_Catalog_Model_Category::CACHE_TAG . '_' .
37
  $this->_getCategoryIdForCache();
38
 
@@ -83,4 +83,24 @@ class Made_Cache_Block_Catalog_Product_List extends Mage_Catalog_Block_Product_L
83
  Mage::registry('current_tag')
84
  ));
85
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  }
32
  */
33
  public function getCacheTags()
34
  {
35
+ $tags = array();
36
  $tags[] = Mage_Catalog_Model_Category::CACHE_TAG . '_' .
37
  $this->_getCategoryIdForCache();
38
 
83
  Mage::registry('current_tag')
84
  ));
85
  }
86
+
87
+ /**
88
+ * For granular caching of product list blocks. Requires the markup
89
+ * of a single product to be broken out of list.phtml into
90
+ * catalog/product/list/product.phtml
91
+ *
92
+ * @param Mage_Catalog_Model_Product $product
93
+ * @return type
94
+ */
95
+ public function getProductHtml($product)
96
+ {
97
+ $name = 'prod_list_prod_' . $product->getId();
98
+ $block = $this->getLayout()->createBlock('cache/catalog_product_list_product')
99
+ ->setName($name)
100
+ ->setCacheLifetime($this->getCacheLifetime())
101
+ ->setTemplate('catalog/product/list/product.phtml')
102
+ ->setProduct($product);
103
+
104
+ return $block->toHtml();
105
+ }
106
  }
app/code/community/Made/Cache/Block/Catalog/Product/List/Product.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Granular product list product cache
4
+ *
5
+ * @see Made_Cache_Block_Catalog_Product_List
6
+ * @package Made_Cache
7
+ * @author info@madepeople.se
8
+ * @copyright Copyright (c) 2012 Made People AB. (http://www.madepeople.se/)
9
+ */
10
+ class Made_Cache_Block_Catalog_Product_List_Product
11
+ extends Made_Cache_Block_Catalog_Product_List
12
+ {
13
+ /**
14
+ * Only clear on the product itself
15
+ *
16
+ * @return string
17
+ */
18
+ public function getCacheTags()
19
+ {
20
+ $tags = array(Mage_Catalog_Model_Product::CACHE_TAG . '_' . $this->getProduct()->getId());
21
+ return $tags;
22
+ }
23
+
24
+ /**
25
+ * Product unique - not category
26
+ *
27
+ * @return array
28
+ */
29
+ public function getCacheKeyInfo()
30
+ {
31
+ $keys = parent::getCacheKeyInfo();
32
+ if (!is_array($keys)) {
33
+ $keys = array();
34
+ }
35
+
36
+ $_taxCalculator = Mage::getModel('tax/calculation');
37
+ $_customer = Mage::getSingleton('customer/session')->getCustomer();
38
+ $_product = $this->getProduct();
39
+
40
+ return array_merge($keys, array(
41
+ $_product->getId(),
42
+ Mage::app()->getStore()->getCode(),
43
+ $_customer->getGroupId(),
44
+ $_taxCalculator->getRate(
45
+ $_taxCalculator->getRateRequest()
46
+ ->setProductClassId($_product->getTaxClassId())
47
+ )
48
+ ));
49
+ }
50
+
51
+ /**
52
+ * No default values should be used
53
+ *
54
+ * @return string
55
+ */
56
+ public function getCacheKey()
57
+ {
58
+ $key = $this->getCacheKeyInfo();
59
+ $key = array_values($key); // Ignore array keys
60
+ $key = implode('|', $key);
61
+ $key = sha1($key);
62
+ return $key;
63
+ }
64
+
65
+ /**
66
+ * We can't cache the return URL, no idea where the cache came from and
67
+ * it can't be user-dependent
68
+ *
69
+ * @param Mage_Catalog_Model_Product $product
70
+ * @param array $additional
71
+ */
72
+ public function getAddToCartUrl($product, $additional = array())
73
+ {
74
+ $url = parent::getAddToCartUrl($product, $additional);
75
+ $url = preg_replace('#/uenc/[^/]+/#', '/', $url);
76
+ return $url;
77
+ }
78
+ }
app/code/community/Made/Cache/Block/Catalog/Product/View.php CHANGED
@@ -35,7 +35,7 @@ class Made_Cache_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_V
35
  */
36
  public function getCacheTags()
37
  {
38
- $tags = parent::getCacheTags();
39
  $tags[] = Mage_Catalog_Model_Product::CACHE_TAG . '_'
40
  . $this->getProduct()->getId();
41
  return $tags;
35
  */
36
  public function getCacheTags()
37
  {
38
+ $tags = array();
39
  $tags[] = Mage_Catalog_Model_Product::CACHE_TAG . '_'
40
  . $this->getProduct()->getId();
41
  return $tags;
app/code/community/Made/Cache/Model/Observer.php CHANGED
@@ -53,4 +53,21 @@ class Made_Cache_Model_Observer
53
  $transport->setHtml($html);
54
  }
55
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  }
53
  $transport->setHtml($html);
54
  }
55
  }
56
+
57
+ /**
58
+ * CatalogRule invalidates cache on product save, so this must be cleaned
59
+ *
60
+ * @param Varien_Event_Observer $observer
61
+ */
62
+ public function cleanCacheAfterProductSave(Varien_Event_Observer $observer)
63
+ {
64
+ $invalidatedTypes = Mage::app()->getCacheInstance()
65
+ ->getInvalidatedTypes();
66
+
67
+ if (is_array($invalidatedTypes) &&
68
+ isset($invalidatedTypes[Mage_Core_Block_Abstract::CACHE_GROUP])) {
69
+ Mage::app()->getCacheInstance()
70
+ ->cleanType(Mage_Core_Block_Abstract::CACHE_GROUP);
71
+ }
72
+ }
73
  }
app/code/community/Made/Cache/etc/config.xml CHANGED
@@ -9,7 +9,7 @@
9
  <config>
10
  <modules>
11
  <Made_Cache>
12
- <version>1.0.3</version>
13
  </Made_Cache>
14
  </modules>
15
  <global>
@@ -24,6 +24,9 @@
24
  </core>
25
  </models>
26
  <blocks>
 
 
 
27
  <catalog>
28
  <rewrite>
29
  <product_view>Made_Cache_Block_Catalog_Product_View</product_view>
@@ -57,6 +60,15 @@
57
  </cache_add_esi_tags>
58
  </observers>
59
  </core_block_abstract_to_html_after>
 
 
 
 
 
 
 
 
 
60
  </events>
61
  </global>
62
  <frontend>
9
  <config>
10
  <modules>
11
  <Made_Cache>
12
+ <version>1.0.4</version>
13
  </Made_Cache>
14
  </modules>
15
  <global>
24
  </core>
25
  </models>
26
  <blocks>
27
+ <cache>
28
+ <class>Made_Cache_Block</class>
29
+ </cache>
30
  <catalog>
31
  <rewrite>
32
  <product_view>Made_Cache_Block_Catalog_Product_View</product_view>
60
  </cache_add_esi_tags>
61
  </observers>
62
  </core_block_abstract_to_html_after>
63
+ <controller_action_postdispatch_adminhtml_catalog_product_save>
64
+ <observers>
65
+ <clean_cache_after_product_save>
66
+ <type>singleton</type>
67
+ <class>cache/observer</class>
68
+ <method>cleanCacheAfterProductSave</method>
69
+ </clean_cache_after_product_save>
70
+ </observers>
71
+ </controller_action_postdispatch_adminhtml_catalog_product_save>
72
  </events>
73
  </global>
74
  <frontend>
package.xml CHANGED
@@ -1,7 +1,7 @@
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,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-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>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Made_Cache</name>
4
+ <version>1.0.4</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-10</date>
22
+ <time>12:03:22</time>
23
+ <contents><target name="magecommunity"><dir name="Made"><dir name="Cache"><dir name="Block"><dir name="Catalog"><dir name="Product"><dir name="List"><file name="Product.php" hash="ba8d5fba2fa01d571333e72146d80d40"/></dir><file name="List.php" hash="377798f55bcbe90fda0d3dd582bbea77"/><file name="View.php" hash="14a2b6a99872a0fbbfc9e5390f56642b"/></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="876dd58121c8554ef885316a8126c5c4"/></dir><dir name="controllers"><file name="VarnishController.php" hash="6e7207e07c5385568061b853eeca96fd"/></dir><dir name="etc"><file name="config.xml" hash="0536d9290ef7d8999801ff106497698f"/></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>