Made_Cache - Version 1.0.8

Version Notes

N/A

Download this release

Release Info

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


Code changes from version 1.0.7 to 1.0.8

app/code/community/Made/Cache/Block/Checkout/Cart/Item/Renderer.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Made_Cache
4
+ * @author info@madepeople.se
5
+ * @copyright Copyright (c) 2012 Made People AB. (http://www.madepeople.se/)
6
+ */
7
+ class Made_Cache_Block_Checkout_Cart_Item_Renderer
8
+ extends Mage_Checkout_Block_Cart_Item_Renderer
9
+ {
10
+ /**
11
+ * Get item delete url without the redirect info as we don't know
12
+ * where the item has been cached
13
+ *
14
+ * @return string
15
+ */
16
+ public function getDeleteUrl()
17
+ {
18
+ return $this->getUrl(
19
+ 'checkout/cart/delete',
20
+ array(
21
+ 'id'=>$this->getItem()->getId(),
22
+ )
23
+ );
24
+ }
25
+ }
app/code/community/Made/Cache/Model/Layout.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
- * Injects custom layout XML attributes and handles arbitrary block rendering
4
- * including different layout handle definitions
5
  *
6
  * @package Made_Cache
7
  * @author info@madepeople.se
@@ -31,10 +31,7 @@ class Made_Cache_Model_Layout extends Mage_Core_Model_Layout
31
  const DEFAULT_CACHE_LIFETIME = 9999999999;
32
 
33
  /**
34
- * Aggregate <reference> tags into the final XML to be able to
35
- * determine if child blocks should be instantiated or not, as well as
36
- * not try to render blocks in vain. This is also essential for
37
- * hole-punching
38
  *
39
  * @return Mage_Core_Model_Layout
40
  */
@@ -42,30 +39,6 @@ class Made_Cache_Model_Layout extends Mage_Core_Model_Layout
42
  {
43
  parent::generateXml();
44
  $xml = $this->getNode();
45
- $doc = new DOMDocument;
46
- $doc->loadXML($xml->asXML());
47
- $xpath = new DOMXpath($doc);
48
-
49
- // Aggregate references into one layout tree
50
- $references = $xpath->query("//reference");
51
- foreach ($references as $node) {
52
- $blockName = $node->getAttribute('name');
53
- $nodeList = $xpath->query("//block[@name='".$blockName."']");
54
- if ($nodeList->length) {
55
- $blockNode = $nodeList->item(0);
56
- if ($node->hasChildNodes()) {
57
- $childNodes = $xpath->query('*', $node);
58
- foreach ($childNodes as $child) {
59
- if ($child->nodeType == XML_ELEMENT_NODE) {
60
- $blockNode->appendChild($child);
61
- }
62
- }
63
- }
64
- }
65
- $node->parentNode->removeChild($node);
66
- }
67
- $xml = new Mage_Core_Model_Layout_Element($doc->saveXML());
68
- $this->setXml($xml);
69
 
70
  // Find blocks to cache
71
  $cacheList = $xml->xpath("//cache/*");
@@ -118,25 +91,7 @@ class Made_Cache_Model_Layout extends Mage_Core_Model_Layout
118
  if (empty($parent)) {
119
  $parent = $this->getNode();
120
  }
121
-
122
- // Don't cache children if parent is already cached
123
- $parentName = $parent->getAttribute('name');
124
- if ($parentName) {
125
- if (!isset($this->_blocks[$parentName])) {
126
- return;
127
- }
128
-
129
- $parentBlock = $this->_blocks[$parentName];
130
-
131
- if (!is_null($parentBlock->getCacheLifetime()) &&
132
- Mage::app()->useCache(Mage_Core_Block_Abstract::CACHE_GROUP)) {
133
- $cacheKey = $parentBlock->getCacheKey();
134
- $cacheData = Mage::app()->loadCache($cacheKey);
135
- if ($cacheData) {
136
- return;
137
- }
138
- }
139
- }
140
  return parent::generateBlocks($parent);
141
  }
142
 
1
  <?php
2
  /**
3
+ * Handles arbitrary block rendering including different layout
4
+ * handle definitions
5
  *
6
  * @package Made_Cache
7
  * @author info@madepeople.se
31
  const DEFAULT_CACHE_LIFETIME = 9999999999;
32
 
33
  /**
34
+ * Take cache/noache/ESI tags into concern for block rendering
 
 
 
35
  *
36
  * @return Mage_Core_Model_Layout
37
  */
39
  {
40
  parent::generateXml();
41
  $xml = $this->getNode();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  // Find blocks to cache
44
  $cacheList = $xml->xpath("//cache/*");
91
  if (empty($parent)) {
92
  $parent = $this->getNode();
93
  }
94
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  return parent::generateBlocks($parent);
96
  }
97
 
app/code/community/Made/Cache/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
  /**
4
  * @package Made_Cache
5
  * @author info@madepeople.se
6
- * @copyright Copyright (c) 2011 Made People AB. (http://www.madepeople.se/)
7
  */
8
  -->
9
  <config>
@@ -43,6 +43,7 @@
43
  <checkout>
44
  <rewrite>
45
  <cart_sidebar>Made_Cache_Block_Checkout_Cart_Sidebar</cart_sidebar>
 
46
  </rewrite>
47
  </checkout>
48
  </blocks>
3
  /**
4
  * @package Made_Cache
5
  * @author info@madepeople.se
6
+ * @copyright Copyright (c) 2012 Made People AB. (http://www.madepeople.se/)
7
  */
8
  -->
9
  <config>
43
  <checkout>
44
  <rewrite>
45
  <cart_sidebar>Made_Cache_Block_Checkout_Cart_Sidebar</cart_sidebar>
46
+ <cart_item_renderer>Made_Cache_Block_Checkout_Cart_Item_Renderer</cart_item_renderer>
47
  </rewrite>
48
  </checkout>
49
  </blocks>
app/code/community/Made/Cache/etc/magento.vcl ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This is a basic VCL configuration file for PageCache powered by Varnish for Magento module.
2
+ #
3
+ # Modifications for use with ESI tags and Made_Cache
4
+ #
5
+
6
+ # default backend definition. Set this to point to your content server.
7
+ backend default {
8
+ .host = "127.0.0.1";
9
+ .port = "9000";
10
+ }
11
+
12
+ # admin backend with longer timeout values. Set this to the same IP & port as your default server.
13
+ backend admin {
14
+ .host = "127.0.0.1";
15
+ .port = "9000";
16
+ .first_byte_timeout = 18000s;
17
+ .between_bytes_timeout = 18000s;
18
+ }
19
+
20
+ # add your Magento server IP to allow purges from the backend
21
+ acl purge {
22
+ "localhost";
23
+ "127.0.0.1";
24
+ }
25
+
26
+ sub vcl_recv {
27
+ if (req.restarts == 0) {
28
+ if (req.http.x-forwarded-for) {
29
+ set req.http.X-Forwarded-For =
30
+ req.http.X-Forwarded-For + ", " + client.ip;
31
+ } else {
32
+ set req.http.X-Forwarded-For = client.ip;
33
+ }
34
+ }
35
+
36
+ if (req.request != "GET" &&
37
+ req.request != "HEAD" &&
38
+ req.request != "PUT" &&
39
+ req.request != "POST" &&
40
+ req.request != "TRACE" &&
41
+ req.request != "OPTIONS" &&
42
+ req.request != "DELETE" &&
43
+ req.request != "PURGE") {
44
+ /* Non-RFC2616 or CONNECT which is weird. */
45
+ return (pipe);
46
+ }
47
+
48
+ # purge request
49
+ if (req.request == "PURGE") {
50
+ if (!client.ip ~ purge) {
51
+ error 405 "Not allowed.";
52
+ }
53
+ ban("obj.http.X-Purge-Host ~ " + req.http.X-Purge-Host + " && obj.http.X-Purge-URL ~ " + req.http.X-Purge-Regex + " && obj.http.Content-Type ~ " + req.http.X-Purge-Content-Type);
54
+ error 200 "Purged.";
55
+ }
56
+
57
+ # switch to admin backend configuration
58
+ if (req.http.cookie ~ "adminhtml=") {
59
+ set req.backend = admin;
60
+ }
61
+
62
+ # we only deal with GET and HEAD by default
63
+ if (req.request != "GET" && req.request != "HEAD") {
64
+ return (pass);
65
+ }
66
+
67
+ # normalize url in case of leading HTTP scheme and domain
68
+ set req.url = regsub(req.url, "^http[s]?://[^/]+", "");
69
+
70
+ # static files are always cacheable. remove SSL flag and cookie
71
+ if (req.url ~ "^/(media|js|skin)/.*\.(png|jpg|jpeg|gif|css|js|swf|ico)$") {
72
+ unset req.http.Https;
73
+ unset req.http.Cookie;
74
+ }
75
+
76
+ # not cacheable by default
77
+ if (req.http.Authorization || req.http.Https) {
78
+ return (pass);
79
+ }
80
+
81
+ # do not cache any page from
82
+ # - index files
83
+ # - ...
84
+ if (req.url ~ "^/(index)") {
85
+ return (pass);
86
+ }
87
+
88
+ # as soon as we have a NO_CACHE cookie pass request
89
+ #if (req.http.cookie ~ "NO_CACHE=") {
90
+ # return (pass);
91
+ #}
92
+
93
+ # normalize Aceept-Encoding header
94
+ # http://varnish.projects.linpro.no/wiki/FAQ/Compression
95
+ if (req.http.Accept-Encoding) {
96
+ if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
97
+ # No point in compressing these
98
+ remove req.http.Accept-Encoding;
99
+ } elsif (req.http.Accept-Encoding ~ "gzip") {
100
+ set req.http.Accept-Encoding = "gzip";
101
+ } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
102
+ set req.http.Accept-Encoding = "deflate";
103
+ } else {
104
+ # unkown algorithm
105
+ remove req.http.Accept-Encoding;
106
+ }
107
+ }
108
+
109
+ # remove Google gclid parameters
110
+ set req.url = regsuball(req.url,"\?gclid=[^&]+$",""); # strips when QS = "?gclid=AAA"
111
+ set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar"
112
+ set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz"
113
+
114
+ return (lookup);
115
+ }
116
+
117
+ # sub vcl_pipe {
118
+ # # Note that only the first request to the backend will have
119
+ # # X-Forwarded-For set. If you use X-Forwarded-For and want to
120
+ # # have it set for all requests, make sure to have:
121
+ # # set bereq.http.connection = "close";
122
+ # # here. It is not set by default as it might break some broken web
123
+ # # applications, like IIS with NTLM authentication.
124
+ # return (pipe);
125
+ # }
126
+ #
127
+ # sub vcl_pass {
128
+ # return (pass);
129
+ # }
130
+ #
131
+ sub vcl_hash {
132
+ hash_data(req.url);
133
+ if (req.http.host) {
134
+ hash_data(req.http.host);
135
+ } else {
136
+ hash_data(server.ip);
137
+ }
138
+ if (!(req.url ~ "^/(media|js|skin)/.*\.(png|jpg|jpeg|gif|css|js|swf|ico)$")) {
139
+ call design_exception;
140
+ }
141
+ return (hash);
142
+ }
143
+ #
144
+ # sub vcl_hit {
145
+ # return (deliver);
146
+ # }
147
+ #
148
+ # sub vcl_miss {
149
+ # return (fetch);
150
+ # }
151
+
152
+ sub vcl_fetch {
153
+ if (req.url ~ "/madecache/varnish/") {
154
+ return (hit_for_pass);
155
+ }
156
+
157
+ if (beresp.status == 500) {
158
+ set beresp.saintmode = 10s;
159
+ return (restart);
160
+ }
161
+ set beresp.grace = 5m;
162
+
163
+ # add ban-lurker tags to object
164
+ set beresp.http.X-Purge-URL = req.url;
165
+ set beresp.http.X-Purge-Host = req.http.host;
166
+
167
+ if (beresp.status == 200 || beresp.status == 301 || beresp.status == 404) {
168
+ if (beresp.http.Content-Type ~ "text/html" || beresp.http.Content-Type ~ "text/xml") {
169
+ set beresp.do_esi = true;
170
+ if ((beresp.http.Set-Cookie ~ "NO_CACHE=") || (beresp.ttl < 1s)) {
171
+ set beresp.ttl = 0s;
172
+ return (hit_for_pass);
173
+ }
174
+
175
+ # marker for vcl_deliver to reset Age:
176
+ set beresp.http.magicmarker = "1";
177
+
178
+ # Don't cache cookies
179
+ unset beresp.http.set-cookie;
180
+ } else {
181
+ # set default TTL value for static content
182
+ set beresp.ttl = 4h;
183
+ }
184
+ return (deliver);
185
+ }
186
+
187
+ return (hit_for_pass);
188
+ }
189
+
190
+ sub vcl_deliver {
191
+ # debug info
192
+ if (resp.http.X-Cache-Debug) {
193
+ if (obj.hits > 0) {
194
+ set resp.http.X-Cache = "HIT";
195
+ set resp.http.X-Cache-Hits = obj.hits;
196
+ } else {
197
+ set resp.http.X-Cache = "MISS";
198
+ }
199
+ set resp.http.X-Cache-Expires = resp.http.Expires;
200
+ } else {
201
+ # remove Varnish/proxy header
202
+ remove resp.http.X-Varnish;
203
+ remove resp.http.Via;
204
+ remove resp.http.Age;
205
+ remove resp.http.X-Purge-URL;
206
+ remove resp.http.X-Purge-Host;
207
+ }
208
+
209
+ if (resp.http.magicmarker) {
210
+ # Remove the magic marker
211
+ unset resp.http.magicmarker;
212
+
213
+ set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
214
+ set resp.http.Pragma = "no-cache";
215
+ set resp.http.Expires = "Mon, 31 Mar 2008 10:00:00 GMT";
216
+ set resp.http.Age = "0";
217
+ }
218
+ }
219
+
220
+ # sub vcl_error {
221
+ # set obj.http.Content-Type = "text/html; charset=utf-8";
222
+ # set obj.http.Retry-After = "5";
223
+ # synthetic {"
224
+ # <?xml version="1.0" encoding="utf-8"?>
225
+ # <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
226
+ # "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
227
+ # <html>
228
+ # <head>
229
+ # <title>"} + obj.status + " " + obj.response + {"</title>
230
+ # </head>
231
+ # <body>
232
+ # <h1>Error "} + obj.status + " " + obj.response + {"</h1>
233
+ # <p>"} + obj.response + {"</p>
234
+ # <h3>Guru Meditation:</h3>
235
+ # <p>XID: "} + req.xid + {"</p>
236
+ # <hr>
237
+ # <p>Varnish cache server</p>
238
+ # </body>
239
+ # </html>
240
+ # "};
241
+ # return (deliver);
242
+ # }
243
+ #
244
+ # sub vcl_init {
245
+ # return (ok);
246
+ # }
247
+ #
248
+ # sub vcl_fini {
249
+ # return (ok);
250
+ # }
251
+
252
+ sub design_exception {
253
+ }
app/design/frontend/base/default/layout/madecache.xml CHANGED
@@ -3,7 +3,7 @@
3
  /**
4
  * @package Made_Cache
5
  * @author info@madepeople.se
6
- * @copyright Copyright (c) 2011 Made People AB. (http://www.madepeople.se/)
7
  */
8
  -->
9
  <layout version="0.1.0">
3
  /**
4
  * @package Made_Cache
5
  * @author info@madepeople.se
6
+ * @copyright Copyright (c) 2012 Made People AB. (http://www.madepeople.se/)
7
  */
8
  -->
9
  <layout version="0.1.0">
package.xml CHANGED
@@ -1,12 +1,12 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Made_Cache</name>
4
- <version>1.0.7</version>
5
  <stability>stable</stability>
6
  <license>OSL 3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Advanced Block Cache module that enhances performance by implementing cache on the most commonly rendered blocks.</summary>
10
  <description>Few know that Magento out of the box doesn't actually cache anything other than the Navigation and Footer blocks, which are basically static as it is.&#xD;
11
  &#xD;
12
  This module enhances performance by allowing developers to cache any block they want via simple layout xml changes - per layout handle.&#xD;
@@ -17,10 +17,10 @@ ESI is supported in conjunction with Phoenix_VarnishCache, and allows for super-
17
  &#xD;
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-13</date>
22
- <time>18:53:57</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="6356fde9c5acf5f0a96851e780a691b1"/></dir><file name="List.php" hash="377798f55bcbe90fda0d3dd582bbea77"/><file name="View.php" hash="14a2b6a99872a0fbbfc9e5390f56642b"/></dir></dir><dir name="Checkout"><dir name="Cart"><file name="Sidebar.php" hash="f2c2c2c53e791b94e23ac635894213a0"/></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="d7ceee78dd8294b32af75280795cc23c"/><file name="Observer.php" hash="3d8aaad098e61bfd20c9701234ec7266"/></dir><dir name="controllers"><file name="VarnishController.php" hash="6ae7446eef83e106c56b0f05711c3ffa"/></dir><dir name="etc"><file name="config.xml" hash="30195c4aad4535bae9f47079c7d851c8"/></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="6a0f95410f1aed85851bcab8437b53e8"/></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.8</version>
5
  <stability>stable</stability>
6
  <license>OSL 3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Advanced Block Cache module that enhances performance by implementing arbitrary block cache with support for Varnish ESI tags.</summary>
10
  <description>Few know that Magento out of the box doesn't actually cache anything other than the Navigation and Footer blocks, which are basically static as it is.&#xD;
11
  &#xD;
12
  This module enhances performance by allowing developers to cache any block they want via simple layout xml changes - per layout handle.&#xD;
17
  &#xD;
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_made</user><email>info@madepeople.se</email></author></authors>
21
+ <date>2012-05-14</date>
22
+ <time>13:27:45</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="6356fde9c5acf5f0a96851e780a691b1"/></dir><file name="List.php" hash="377798f55bcbe90fda0d3dd582bbea77"/><file name="View.php" hash="14a2b6a99872a0fbbfc9e5390f56642b"/></dir></dir><dir name="Checkout"><dir name="Cart"><dir name="Item"><file name="Renderer.php" hash="4cc697ffc616bae331d584296a91da1b"/></dir><file name="Sidebar.php" hash="f2c2c2c53e791b94e23ac635894213a0"/></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="f3bf85d778680fb1246416ad5b63e961"/><file name="Observer.php" hash="3d8aaad098e61bfd20c9701234ec7266"/></dir><dir name="controllers"><file name="VarnishController.php" hash="6ae7446eef83e106c56b0f05711c3ffa"/></dir><dir name="etc"><file name="config.xml" hash="a1121d761b3ec8713e2bc6537dcfd0f8"/><file name="magento.vcl" hash="d97e5b6df11bf7e6fb47a4fcaa4e81ae"/></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="e7431217f4b0ddc25b405c26530f9161"/></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>