Nexcessnet_Turpentine - Version 0.5.2

Version Notes

Supports Magento v1.6 and later

Download this release

Release Info

Developer Chris Wells
Extension Nexcessnet_Turpentine
Version 0.5.2
Comparing to
See all releases


Code changes from version 0.5.1 to 0.5.2

app/code/community/Nexcessnet/Turpentine/Helper/Data.php CHANGED
@@ -151,11 +151,14 @@ class Nexcessnet_Turpentine_Helper_Data extends Mage_Core_Helper_Abstract {
151
  * @return string
152
  */
153
  public function freeze( $data ) {
154
- return $this->urlBase64Encode(
 
155
  $this->_getCrypt()->encrypt(
156
  gzdeflate(
157
  serialize( $data ),
158
  self::COMPRESSION_LEVEL ) ) );
 
 
159
  }
160
 
161
  /**
@@ -165,10 +168,13 @@ class Nexcessnet_Turpentine_Helper_Data extends Mage_Core_Helper_Abstract {
165
  * @return mixed
166
  */
167
  public function thaw( $data ) {
168
- return unserialize(
 
169
  gzinflate(
170
  $this->_getCrypt()->decrypt(
171
  $this->urlBase64Decode( $data ) ) ) );
 
 
172
  }
173
 
174
  /**
@@ -243,6 +249,7 @@ class Nexcessnet_Turpentine_Helper_Data extends Mage_Core_Helper_Abstract {
243
  * @return array
244
  */
245
  protected function _getChildBlockNames( $blockNode ) {
 
246
  if( $blockNode instanceof Mage_Core_Model_Layout_Element ) {
247
  $blockNames = array( (string)$blockNode['name'] );
248
  foreach( $blockNode->xpath( './block | ./reference' ) as $childBlockNode ) {
@@ -252,6 +259,7 @@ class Nexcessnet_Turpentine_Helper_Data extends Mage_Core_Helper_Abstract {
252
  } else {
253
  $blockNames = array();
254
  }
 
255
  return $blockNames;
256
  }
257
 
151
  * @return string
152
  */
153
  public function freeze( $data ) {
154
+ Varien_Profiler::start( 'turpentine::helper::data::freeze' );
155
+ $frozenData = $this->urlBase64Encode(
156
  $this->_getCrypt()->encrypt(
157
  gzdeflate(
158
  serialize( $data ),
159
  self::COMPRESSION_LEVEL ) ) );
160
+ Varien_Profiler::stop( 'turpentine::helper::data::freeze' );
161
+ return $frozenData;
162
  }
163
 
164
  /**
168
  * @return mixed
169
  */
170
  public function thaw( $data ) {
171
+ Varien_Profiler::start( 'turpentine::helper::data::thaw' );
172
+ $thawedData = unserialize(
173
  gzinflate(
174
  $this->_getCrypt()->decrypt(
175
  $this->urlBase64Decode( $data ) ) ) );
176
+ Varien_Profiler::stop( 'turpentine::helper::data::thaw' );
177
+ return $thawedData;
178
  }
179
 
180
  /**
249
  * @return array
250
  */
251
  protected function _getChildBlockNames( $blockNode ) {
252
+ Varien_Profiler::start( 'turpentine::helper::data::_getChildBlockNames' );
253
  if( $blockNode instanceof Mage_Core_Model_Layout_Element ) {
254
  $blockNames = array( (string)$blockNode['name'] );
255
  foreach( $blockNode->xpath( './block | ./reference' ) as $childBlockNode ) {
259
  } else {
260
  $blockNames = array();
261
  }
262
+ Varien_Profiler::stop( 'turpentine::helper::data::_getChildBlockNames' );
263
  return $blockNames;
264
  }
265
 
app/code/community/Nexcessnet/Turpentine/Helper/Esi.php CHANGED
@@ -193,6 +193,7 @@ class Nexcessnet_Turpentine_Helper_Esi extends Mage_Core_Helper_Abstract {
193
  * @return array
194
  */
195
  public function getCacheClearEvents() {
 
196
  $cacheKey = $this->getCacheClearEventsCacheKey();
197
  $events = @unserialize( Mage::app()->loadCache( $cacheKey ) );
198
  if( is_null( $events ) || $events === false ) {
@@ -200,6 +201,7 @@ class Nexcessnet_Turpentine_Helper_Esi extends Mage_Core_Helper_Abstract {
200
  Mage::app()->saveCache( serialize( $events ), $cacheKey,
201
  array( 'LAYOUT_GENERAL_CACHE_TAG' ) );
202
  }
 
203
  return array_merge( $this->getDefaultCacheClearEvents(), $events );
204
  }
205
 
@@ -209,7 +211,7 @@ class Nexcessnet_Turpentine_Helper_Esi extends Mage_Core_Helper_Abstract {
209
  * @return string
210
  */
211
  public function getDefaultEsiTtl() {
212
- return Mage::getStoreConfig( 'web/cookie/cookie_lifetime' );
213
  }
214
 
215
  /**
@@ -241,8 +243,9 @@ class Nexcessnet_Turpentine_Helper_Esi extends Mage_Core_Helper_Abstract {
241
  * @return Mage_Core_Model_Layout_Element|SimpleXMLElement
242
  */
243
  public function getLayoutXml() {
 
244
  if( is_null( $this->_layoutXml ) ) {
245
- if( Mage::app()->useCache( 'layout' ) ) {
246
  $cacheKey = $this->getFileLayoutUpdatesXmlCacheKey();
247
  $this->_layoutXml = simplexml_load_string(
248
  Mage::app()->loadCache( $cacheKey ) );
@@ -250,12 +253,13 @@ class Nexcessnet_Turpentine_Helper_Esi extends Mage_Core_Helper_Abstract {
250
  // this check is redundant if the layout cache is disabled
251
  if( !$this->_layoutXml ) {
252
  $this->_layoutXml = $this->_loadLayoutXml();
253
- }
254
- if( Mage::app()->useCache( 'layout' ) ) {
255
- Mage::app()->saveCache( $this->_layoutXml->asXML(),
256
- $cacheKey, array( 'LAYOUT_GENERAL_CACHE_TAG' ) );
257
  }
258
  }
 
259
  return $this->_layoutXml;
260
  }
261
 
@@ -299,6 +303,7 @@ class Nexcessnet_Turpentine_Helper_Esi extends Mage_Core_Helper_Abstract {
299
  * @return array
300
  */
301
  protected function _loadEsiCacheClearEvents() {
 
302
  $layoutXml = $this->getLayoutXml();
303
  $events = $layoutXml->xpath(
304
  '//action[@method=\'setEsiOptions\']/params/flush_events/*' );
@@ -310,6 +315,7 @@ class Nexcessnet_Turpentine_Helper_Esi extends Mage_Core_Helper_Abstract {
310
  } else {
311
  $events = array();
312
  }
 
313
  return $events;
314
  }
315
 
@@ -319,6 +325,7 @@ class Nexcessnet_Turpentine_Helper_Esi extends Mage_Core_Helper_Abstract {
319
  * @return Mage_Core_Model_Layout_Element
320
  */
321
  protected function _loadLayoutXml() {
 
322
  $design = Mage::getDesign();
323
  $layoutXml = Mage::getSingleton( 'core/layout' )
324
  ->getUpdate()
@@ -327,6 +334,7 @@ class Nexcessnet_Turpentine_Helper_Esi extends Mage_Core_Helper_Abstract {
327
  $design->getPackageName(),
328
  $design->getTheme( 'layout' ),
329
  Mage::app()->getStore()->getId() );
 
330
  return $layoutXml;
331
  }
332
  }
193
  * @return array
194
  */
195
  public function getCacheClearEvents() {
196
+ Varien_Profiler::start( 'turpentine::helper::esi::getCacheClearEvents' );
197
  $cacheKey = $this->getCacheClearEventsCacheKey();
198
  $events = @unserialize( Mage::app()->loadCache( $cacheKey ) );
199
  if( is_null( $events ) || $events === false ) {
201
  Mage::app()->saveCache( serialize( $events ), $cacheKey,
202
  array( 'LAYOUT_GENERAL_CACHE_TAG' ) );
203
  }
204
+ Varien_Profiler::stop( 'turpentine::helper::esi::getCacheClearEvents' );
205
  return array_merge( $this->getDefaultCacheClearEvents(), $events );
206
  }
207
 
211
  * @return string
212
  */
213
  public function getDefaultEsiTtl() {
214
+ return trim( Mage::getStoreConfig( 'web/cookie/cookie_lifetime' ) );
215
  }
216
 
217
  /**
243
  * @return Mage_Core_Model_Layout_Element|SimpleXMLElement
244
  */
245
  public function getLayoutXml() {
246
+ Varien_Profiler::start( 'turpentine::helper::esi::getLayoutXml' );
247
  if( is_null( $this->_layoutXml ) ) {
248
+ if( $useCache = Mage::app()->useCache( 'layout' ) ) {
249
  $cacheKey = $this->getFileLayoutUpdatesXmlCacheKey();
250
  $this->_layoutXml = simplexml_load_string(
251
  Mage::app()->loadCache( $cacheKey ) );
253
  // this check is redundant if the layout cache is disabled
254
  if( !$this->_layoutXml ) {
255
  $this->_layoutXml = $this->_loadLayoutXml();
256
+ if( $useCache ) {
257
+ Mage::app()->saveCache( $this->_layoutXml->asXML(),
258
+ $cacheKey, array( 'LAYOUT_GENERAL_CACHE_TAG' ) );
259
+ }
260
  }
261
  }
262
+ Varien_Profiler::stop( 'turpentine::helper::esi::getLayoutXml' );
263
  return $this->_layoutXml;
264
  }
265
 
303
  * @return array
304
  */
305
  protected function _loadEsiCacheClearEvents() {
306
+ Varien_Profiler::start( 'turpentine::helper::esi::_loadEsiCacheClearEvents' );
307
  $layoutXml = $this->getLayoutXml();
308
  $events = $layoutXml->xpath(
309
  '//action[@method=\'setEsiOptions\']/params/flush_events/*' );
315
  } else {
316
  $events = array();
317
  }
318
+ Varien_Profiler::stop( 'turpentine::helper::esi::_loadEsiCacheClearEvents' );
319
  return $events;
320
  }
321
 
325
  * @return Mage_Core_Model_Layout_Element
326
  */
327
  protected function _loadLayoutXml() {
328
+ Varien_Profiler::start( 'turpentine::helper::esi::_loadLayoutXml' );
329
  $design = Mage::getDesign();
330
  $layoutXml = Mage::getSingleton( 'core/layout' )
331
  ->getUpdate()
334
  $design->getPackageName(),
335
  $design->getTheme( 'layout' ),
336
  Mage::app()->getStore()->getId() );
337
+ Varien_Profiler::stop( 'turpentine::helper::esi::_loadLayoutXml' );
338
  return $layoutXml;
339
  }
340
  }
app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php CHANGED
@@ -53,9 +53,9 @@ class Nexcessnet_Turpentine_Model_Observer_Ban extends Varien_Event_Observer {
53
  $sessionId = Mage::app()->getRequest()->getCookie( 'frontend' );
54
  if( $sessionId ) {
55
  $result = $this->_getVarnishAdmin()->flushExpression(
56
- 'obj.http.X-Varnish-Session', '~', preg_quote( $sessionId ),
57
  '&&', 'obj.http.X-Turpentine-Flush-Events', '~',
58
- '(^|,)' . preg_quote( $eventName ) . '(,|$)' );
59
  Mage::dispatchEvent( 'turpentine_ban_client_esi_cache', $result );
60
  if( $this->_checkResult( $result ) ) {
61
  Mage::helper( 'turpentine/debug' )
53
  $sessionId = Mage::app()->getRequest()->getCookie( 'frontend' );
54
  if( $sessionId ) {
55
  $result = $this->_getVarnishAdmin()->flushExpression(
56
+ 'obj.http.X-Varnish-Session', '==', $sessionId,
57
  '&&', 'obj.http.X-Turpentine-Flush-Events', '~',
58
+ $eventName );
59
  Mage::dispatchEvent( 'turpentine_ban_client_esi_cache', $result );
60
  if( $this->_checkResult( $result ) ) {
61
  Mage::helper( 'turpentine/debug' )
app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php CHANGED
@@ -76,31 +76,52 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
76
  * @return null
77
  */
78
  public function checkRedirectUrl( $eventObject ) {
 
79
  $url = $eventObject->getTransport()->getUrl();
80
- // TODO: make sure this actually looks like a URL
 
 
81
  $reqUenc = Mage::helper( 'core' )->urlDecode(
82
  Mage::app()->getRequest()->getParam( 'uenc' ) );
83
- $esiHelper = Mage::helper( 'turpentine/esi' );
84
- $dummyUrl = $esiHelper->getDummyUrl();
85
- $getBlockUrlPattern = '~/turpentine/esi/getBlock/~';
86
- if( preg_match( $getBlockUrlPattern, $url ) ||
87
- preg_match( $getBlockUrlPattern, $reqUenc ) ) {
88
- $eventObject->getTransport()->setUrl( $dummyUrl );
89
- } elseif( $reqUenc && Mage::getBaseUrl() == $url ) {
90
- $corsOrigin = $esiHelper->getCorsOrigin();
91
- if( $corsOrigin != $esiHelper->getCorsOrigin( $reqUenc ) ) {
92
- $eventObject->getTransport()->setUrl(
93
- $corsOrigin . parse_url( $reqUenc, PHP_URL_PATH ) );
94
  }
 
 
95
  }
96
 
97
  if( $eventObject->getTransport()->getUrl() != $url ) {
98
  Mage::helper( 'turpentine/debug' )->logDebug(
99
- 'ESI redirect fixup triggered, rewrote: %s => %s',
100
  $url, $eventObject->getTransport()->getUrl() );
101
  }
102
  }
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  /**
105
  * Load the cache clear events from stored config
106
  *
@@ -108,6 +129,7 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
108
  * @return null
109
  */
110
  public function loadCacheClearEvents( $eventObject ) {
 
111
  $events = Mage::helper( 'turpentine/esi' )->getCacheClearEvents();
112
  $appShim = Mage::getSingleton( 'turpentine/shim_mage_core_app' );
113
  foreach( $events as $ccEvent ) {
@@ -115,6 +137,7 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
115
  'turpentine_ban_' . $ccEvent, 'singleton',
116
  'turpentine/observer_ban', 'banClientEsiCache' );
117
  }
 
118
  }
119
 
120
  /**
@@ -150,6 +173,7 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
150
  $debugHelper->logInfo( 'Block check passed, injecting block: %s',
151
  $blockObject->getNameInLayout() );
152
  }
 
153
  $ttlParam = $esiHelper->getEsiTtlParam();
154
  $cacheTypeParam = $esiHelper->getEsiCacheTypeParam();
155
  $dataParam = $esiHelper->getEsiDataParam();
@@ -198,6 +222,7 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
198
  'ESI url is probably too long (%d > 2047 characters): %s',
199
  strlen( $esiUrl ), $esiUrl );
200
  }
 
201
  } // else handle the block like normal and cache it inline with the page
202
  }
203
 
@@ -209,6 +234,7 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
209
  * @return Varien_Object
210
  */
211
  protected function _getEsiData( $blockObject, $esiOptions ) {
 
212
  $esiHelper = Mage::helper( 'turpentine/esi' );
213
  $cacheTypeParam = $esiHelper->getEsiCacheTypeParam();
214
  $scopeParam = $esiHelper->getEsiScopeParam();
@@ -263,6 +289,7 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
263
  }
264
  $esiData->setSimpleRegistry( $simpleRegistry );
265
  $esiData->setComplexRegistry( $complexRegistry );
 
266
  return $esiData;
267
  }
268
 
@@ -287,6 +314,7 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
287
  * @return array
288
  */
289
  protected function _getBlockLayoutHandles( $block ) {
 
290
  $layout = $block->getLayout();
291
  $layoutXml = Mage::helper( 'turpentine/esi' )->getLayoutXml();
292
  $activeHandles = array();
@@ -310,6 +338,7 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
310
  if( !$activeHandles ) {
311
  $activeHandles[] = 'default';
312
  }
 
313
  return array_unique( $activeHandles );
314
  }
315
 
76
  * @return null
77
  */
78
  public function checkRedirectUrl( $eventObject ) {
79
+ $esiHelper = Mage::helper( 'turpentine/esi' );
80
  $url = $eventObject->getTransport()->getUrl();
81
+ $referer = Mage::helper( 'core/http' )->getHttpReferer();
82
+ // $referer = Mage::app()->getRequest()->getHeader( 'Referer' );
83
+ $dummyUrl = $esiHelper->getDummyUrl();
84
  $reqUenc = Mage::helper( 'core' )->urlDecode(
85
  Mage::app()->getRequest()->getParam( 'uenc' ) );
86
+
87
+ if( $this->_checkIsEsiUrl( $url ) ) {
88
+ if( $this->_checkIsNotEsiUrl( $reqUenc ) &&
89
+ Mage::getBaseUrl() == $url ) {
90
+ $newUrl = $this->_fixupUencUrl( $reqUenc );
91
+ } elseif( $this->_checkIsNotEsiUrl( $referer ) ) {
92
+ $newUrl = $referer;
93
+ } else {
94
+ $newUrl = $dummyUrl;
 
 
95
  }
96
+ // TODO: make sure this actually looks like a URL
97
+ $eventObject->getTransport()->setUrl( $newUrl );
98
  }
99
 
100
  if( $eventObject->getTransport()->getUrl() != $url ) {
101
  Mage::helper( 'turpentine/debug' )->logDebug(
102
+ 'Detected redirect to ESI URL, changing: %s => %s',
103
  $url, $eventObject->getTransport()->getUrl() );
104
  }
105
  }
106
 
107
+ protected function _fixupUencUrl( $uencUrl ) {
108
+ $esiHelper = Mage::helper( 'turpentine/esi' );
109
+ $corsOrigin = $esiHelper->getCorsOrigin();
110
+ if( $corsOrigin != $esiHelper->getCorsOrigin( $uencUrl ) ) {
111
+ return $corsOrigin . parse_url( $uencUrl, PHP_URL_PATH );
112
+ } else {
113
+ return $uencUrl;
114
+ }
115
+ }
116
+
117
+ protected function _checkIsNotEsiUrl( $url ) {
118
+ return $url && !preg_match( '~/turpentine/esi/getBlock/~', $url );
119
+ }
120
+
121
+ protected function _checkIsEsiUrl( $url ) {
122
+ return !$this->_checkIsNotEsiUrl( $url );
123
+ }
124
+
125
  /**
126
  * Load the cache clear events from stored config
127
  *
129
  * @return null
130
  */
131
  public function loadCacheClearEvents( $eventObject ) {
132
+ Varien_Profiler::start( 'turpentine::observer::esi::loadCacheClearEvents' );
133
  $events = Mage::helper( 'turpentine/esi' )->getCacheClearEvents();
134
  $appShim = Mage::getSingleton( 'turpentine/shim_mage_core_app' );
135
  foreach( $events as $ccEvent ) {
137
  'turpentine_ban_' . $ccEvent, 'singleton',
138
  'turpentine/observer_ban', 'banClientEsiCache' );
139
  }
140
+ Varien_Profiler::stop( 'turpentine::observer::esi::loadCacheClearEvents' );
141
  }
142
 
143
  /**
173
  $debugHelper->logInfo( 'Block check passed, injecting block: %s',
174
  $blockObject->getNameInLayout() );
175
  }
176
+ Varien_Profiler::start( 'turpentine::observer::esi::injectEsi' );
177
  $ttlParam = $esiHelper->getEsiTtlParam();
178
  $cacheTypeParam = $esiHelper->getEsiCacheTypeParam();
179
  $dataParam = $esiHelper->getEsiDataParam();
222
  'ESI url is probably too long (%d > 2047 characters): %s',
223
  strlen( $esiUrl ), $esiUrl );
224
  }
225
+ Varien_Profiler::stop( 'turpentine::observer::esi::injectEsi' );
226
  } // else handle the block like normal and cache it inline with the page
227
  }
228
 
234
  * @return Varien_Object
235
  */
236
  protected function _getEsiData( $blockObject, $esiOptions ) {
237
+ Varien_Profiler::start( 'turpentine::observer::esi::_getEsiData' );
238
  $esiHelper = Mage::helper( 'turpentine/esi' );
239
  $cacheTypeParam = $esiHelper->getEsiCacheTypeParam();
240
  $scopeParam = $esiHelper->getEsiScopeParam();
289
  }
290
  $esiData->setSimpleRegistry( $simpleRegistry );
291
  $esiData->setComplexRegistry( $complexRegistry );
292
+ Varien_Profiler::stop( 'turpentine::observer::esi::_getEsiData' );
293
  return $esiData;
294
  }
295
 
314
  * @return array
315
  */
316
  protected function _getBlockLayoutHandles( $block ) {
317
+ Varien_Profiler::start( 'turpentine::observer::esi::_getBlockLayoutHandles' );
318
  $layout = $block->getLayout();
319
  $layoutXml = Mage::helper( 'turpentine/esi' )->getLayoutXml();
320
  $activeHandles = array();
338
  if( !$activeHandles ) {
339
  $activeHandles[] = 'default';
340
  }
341
+ Varien_Profiler::stop( 'turpentine::observer::esi::_getBlockLayoutHandles' );
342
  return array_unique( $activeHandles );
343
  }
344
 
app/code/community/Nexcessnet/Turpentine/Model/Session.php CHANGED
@@ -22,8 +22,9 @@
22
  class Nexcessnet_Turpentine_Model_Session extends Mage_Core_Model_Session_Abstract {
23
  protected $_namespace = 'turpentine';
24
 
25
- public function __construct() {
26
- $this->init( $this->_namespace );
 
27
  Mage::dispatchEvent(
28
  sprintf( '%s_session_init', $this->_namespace ),
29
  array( sprintf( '%s_session', $this->_namespace ) => $this ) );
22
  class Nexcessnet_Turpentine_Model_Session extends Mage_Core_Model_Session_Abstract {
23
  protected $_namespace = 'turpentine';
24
 
25
+ public function __construct( $data=array() ) {
26
+ $sessionName = isset( $data['name'] ) ? $data['name'] : null;
27
+ $this->init( $this->_namespace, $sessionName );
28
  Mage::dispatchEvent(
29
  sprintf( '%s_session_init', $this->_namespace ),
30
  array( sprintf( '%s_session', $this->_namespace ) => $this ) );
app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php CHANGED
@@ -121,6 +121,7 @@ class Nexcessnet_Turpentine_EsiController extends Mage_Core_Controller_Front_Act
121
  * @return Mage_Core_Block_Template
122
  */
123
  protected function _getEsiBlock( $esiData ) {
 
124
  foreach( $esiData->getSimpleRegistry() as $key => $value ) {
125
  Mage::register( $key, $value, true );
126
  }
@@ -152,6 +153,7 @@ class Nexcessnet_Turpentine_EsiController extends Mage_Core_Controller_Front_Act
152
  $layout->generateBlocks( $node );
153
  }
154
  }
 
155
  return $layout->getBlock( $esiData->getNameInLayout() );
156
  }
157
 
121
  * @return Mage_Core_Block_Template
122
  */
123
  protected function _getEsiBlock( $esiData ) {
124
+ Varien_Profiler::start( 'turpentine::controller::esi::_getEsiBlock' );
125
  foreach( $esiData->getSimpleRegistry() as $key => $value ) {
126
  Mage::register( $key, $value, true );
127
  }
153
  $layout->generateBlocks( $node );
154
  }
155
  }
156
+ Varien_Profiler::stop( 'turpentine::controller::esi::_getEsiBlock' );
157
  return $layout->getBlock( $esiData->getNameInLayout() );
158
  }
159
 
app/code/community/Nexcessnet/Turpentine/etc/config.xml CHANGED
@@ -20,7 +20,7 @@
20
  <config>
21
  <modules>
22
  <Nexcessnet_Turpentine>
23
- <version>0.5.1</version>
24
  </Nexcessnet_Turpentine>
25
  </modules>
26
  <default>
@@ -73,17 +73,23 @@
73
  </turpentine_vcl>
74
  </default>
75
  <global>
 
 
 
 
 
 
 
 
 
 
 
76
  <ignoredModules>
77
  <entities>
78
- <!--
79
- This disables Magento visitor logging for Turpentine ESI
80
- requests. The logging was pointless and caused AJAX blocks to
81
- take much more time then they otherwise would to load (most of
82
- the time was spent doing database writes)
83
- -->
84
  <turpentine/>
85
  </entities>
86
  </ignoredModules>
 
87
  <blocks>
88
  <turpentine>
89
  <class>Nexcessnet_Turpentine_Block</class>
20
  <config>
21
  <modules>
22
  <Nexcessnet_Turpentine>
23
+ <version>0.5.2</version>
24
  </Nexcessnet_Turpentine>
25
  </modules>
26
  <default>
73
  </turpentine_vcl>
74
  </default>
75
  <global>
76
+ <!--
77
+ This disables Magento visitor logging for Turpentine ESI
78
+ requests. The logging was pointless and caused AJAX blocks to
79
+ take much more time then they otherwise would to load (most of
80
+ the time was spent doing database writes)
81
+ -->
82
+ <!-- Disabled because if the visitor doesn't have any entries in the
83
+ visitor log the product comparison block won't work for non-logged-in
84
+ visitors.
85
+ @see Mage/Catalog/controllers/Product/CompareController.php#79
86
+
87
  <ignoredModules>
88
  <entities>
 
 
 
 
 
 
89
  <turpentine/>
90
  </entities>
91
  </ignoredModules>
92
+ -->
93
  <blocks>
94
  <turpentine>
95
  <class>Nexcessnet_Turpentine_Block</class>
app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl CHANGED
@@ -1,3 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ## Nexcessnet_Turpentine Varnish v2 VCL Template
2
 
3
  ## Custom C Code
@@ -39,17 +56,22 @@ sub remove_double_slashes {
39
  }
40
 
41
  sub generate_session {
42
- # generate a UUID and set the Cookie header to `frontend=$UUID`, overwrites
43
- # any other cookies in the header
44
- C{
45
- char uuid_buf [50];
46
- generate_uuid(uuid_buf);
47
- VRT_SetHdr(sp, HDR_REQ,
48
- "\030X-Varnish-Faked-Session:",
49
- uuid_buf,
50
- vrt_magic_string_end
51
- );
52
- }C
 
 
 
 
 
53
  if (req.http.Cookie) {
54
  # client sent us cookies, just not a frontend cookie. try not to blow
55
  # away the extra cookies
@@ -154,6 +176,7 @@ sub vcl_recv {
154
  req.url ~ ".*\.(?:{{static_extensions}})(?=\?|&|$)") {
155
  # don't need cookies for static assets
156
  remove req.http.Cookie;
 
157
  return (lookup);
158
  }
159
  # this doesn't need a enable_url_excludes because we can be reasonably
@@ -295,7 +318,7 @@ sub vcl_deliver {
295
  call generate_session_expires;
296
  set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session "; expires="
297
  resp.http.X-Varnish-Cookie-Expires "; path="
298
- regsub(regsub(req.url, "{{url_base_regex}}.*", "\1"), "/$", "");
299
  if (req.http.Host) {
300
  set resp.http.Set-Cookie = resp.http.Set-Cookie
301
  "; domain=" regsub(req.http.Host, ":\d+$", "");
1
+ # Nexcess.net Turpentine Extension for Magento
2
+ # Copyright (C) 2012 Nexcess.net L.L.C.
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License along
15
+ # with this program; if not, write to the Free Software Foundation, Inc.,
16
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
+
18
  ## Nexcessnet_Turpentine Varnish v2 VCL Template
19
 
20
  ## Custom C Code
56
  }
57
 
58
  sub generate_session {
59
+ # generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID
60
+ # from SID URL param
61
+ if (req.url ~ ".*[&?]SID=([^&]+).*") {
62
+ set req.http.X-Varnish-Faked-Session = regsub(
63
+ req.url, ".*[&?]SID=([^&]+).*", "frontend=\1");
64
+ } else {
65
+ C{
66
+ char uuid_buf [50];
67
+ generate_uuid(uuid_buf);
68
+ VRT_SetHdr(sp, HDR_REQ,
69
+ "\030X-Varnish-Faked-Session:",
70
+ uuid_buf,
71
+ vrt_magic_string_end
72
+ );
73
+ }C
74
+ }
75
  if (req.http.Cookie) {
76
  # client sent us cookies, just not a frontend cookie. try not to blow
77
  # away the extra cookies
176
  req.url ~ ".*\.(?:{{static_extensions}})(?=\?|&|$)") {
177
  # don't need cookies for static assets
178
  remove req.http.Cookie;
179
+ remove req.http.X-Varnish-Faked-Session;
180
  return (lookup);
181
  }
182
  # this doesn't need a enable_url_excludes because we can be reasonably
318
  call generate_session_expires;
319
  set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session "; expires="
320
  resp.http.X-Varnish-Cookie-Expires "; path="
321
+ regsub(regsub(req.url, "{{url_base_regex}}.*", "\1"), "^(.+)/$", "\1");
322
  if (req.http.Host) {
323
  set resp.http.Set-Cookie = resp.http.Set-Cookie
324
  "; domain=" regsub(req.http.Host, ":\d+$", "");
app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl CHANGED
@@ -1,3 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ## Nexcessnet_Turpentine Varnish v3 VCL Template
2
 
3
  ## Custom C Code
@@ -44,17 +61,22 @@ sub remove_double_slashes {
44
  }
45
 
46
  sub generate_session {
47
- # generate a UUID and set the Cookie header to `frontend=$UUID`, overwrites
48
- # any other cookies in the header
49
- C{
50
- char uuid_buf [50];
51
- generate_uuid(uuid_buf);
52
- VRT_SetHdr(sp, HDR_REQ,
53
- "\030X-Varnish-Faked-Session:",
54
- uuid_buf,
55
- vrt_magic_string_end
56
- );
57
- }C
 
 
 
 
 
58
  if (req.http.Cookie) {
59
  # client sent us cookies, just not a frontend cookie. try not to blow
60
  # away the extra cookies
@@ -152,6 +174,7 @@ sub vcl_recv {
152
  req.url ~ ".*\.(?:{{static_extensions}})(?=\?|&|$)") {
153
  # don't need cookies for static assets
154
  unset req.http.Cookie;
 
155
  return (lookup);
156
  }
157
  # this doesn't need a enable_url_excludes because we can be reasonably
@@ -298,7 +321,7 @@ sub vcl_deliver {
298
  call generate_session_expires;
299
  set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session +
300
  "; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=" +
301
- regsub(regsub(req.url, "{{url_base_regex}}.*", "\1"), "/$", "");
302
  if (req.http.Host) {
303
  set resp.http.Set-Cookie = resp.http.Set-Cookie +
304
  "; domain=" + regsub(req.http.Host, ":\d+$", "");
1
+ # Nexcess.net Turpentine Extension for Magento
2
+ # Copyright (C) 2012 Nexcess.net L.L.C.
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License along
15
+ # with this program; if not, write to the Free Software Foundation, Inc.,
16
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
+
18
  ## Nexcessnet_Turpentine Varnish v3 VCL Template
19
 
20
  ## Custom C Code
61
  }
62
 
63
  sub generate_session {
64
+ # generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID
65
+ # from SID URL param
66
+ if (req.url ~ ".*[&?]SID=([^&]+).*") {
67
+ set req.http.X-Varnish-Faked-Session = regsub(
68
+ req.url, ".*[&?]SID=([^&]+).*", "frontend=\1");
69
+ } else {
70
+ C{
71
+ char uuid_buf [50];
72
+ generate_uuid(uuid_buf);
73
+ VRT_SetHdr(sp, HDR_REQ,
74
+ "\030X-Varnish-Faked-Session:",
75
+ uuid_buf,
76
+ vrt_magic_string_end
77
+ );
78
+ }C
79
+ }
80
  if (req.http.Cookie) {
81
  # client sent us cookies, just not a frontend cookie. try not to blow
82
  # away the extra cookies
174
  req.url ~ ".*\.(?:{{static_extensions}})(?=\?|&|$)") {
175
  # don't need cookies for static assets
176
  unset req.http.Cookie;
177
+ unset req.http.X-Varnish-Faked-Session;
178
  return (lookup);
179
  }
180
  # this doesn't need a enable_url_excludes because we can be reasonably
321
  call generate_session_expires;
322
  set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session +
323
  "; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=" +
324
+ regsub(regsub(req.url, "{{url_base_regex}}.*", "\1"), "^(.+)/$", "\1");
325
  if (req.http.Host) {
326
  set resp.http.Set-Cookie = resp.http.Set-Cookie +
327
  "; domain=" + regsub(req.http.Host, ":\d+$", "");
app/design/frontend/base/default/template/turpentine/esi.phtml CHANGED
@@ -23,6 +23,7 @@ $debugEnabled = (bool)Mage::helper( 'turpentine/esi' )->getEsiDebugEnabled();
23
 
24
  if( $debugEnabled ) {
25
  echo sprintf( '<!-- ESI START [%s] -->', $this->getNameInLayout() ) . PHP_EOL;
 
26
  }
27
  echo sprintf( '<esi:remove>ESI processing not enabled</esi:remove>
28
  <!--esi <esi:include src="%s" /> -->',
23
 
24
  if( $debugEnabled ) {
25
  echo sprintf( '<!-- ESI START [%s] -->', $this->getNameInLayout() ) . PHP_EOL;
26
+ echo sprintf( '<!-- ESI URL: %s -->', $this->getEsiUrl() ) . PHP_EOL;
27
  }
28
  echo sprintf( '<esi:remove>ESI processing not enabled</esi:remove>
29
  <!--esi <esi:include src="%s" /> -->',
package.xml CHANGED
@@ -1 +1 @@
1
- <package><name>Nexcessnet_Turpentine</name><license uri="http://opensource.org/licenses/GPL-2.0">GPLv2</license><notes>Supports Magento v1.6 and later</notes><time>14:18:21</time><__packager>build_package.py v0.0.3</__packager><summary>Improves Magento support for Varnish caching and generates 2.1 and 3.0 compatible VCLs.</summary><stability>stable</stability><__commit_hash>0e87e5abf101bbee21b3a7bb0cd181323a4</__commit_hash><version>0.5.1</version><extends /><contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file hash="a0bd4a5632b369b058c0ec5262e0cc49" name="turpentine.xml" /></dir><dir name="template"><dir name="turpentine"><file hash="b5cae58feecaec4b1c2e4558313c2a3f" name="varnish_management.phtml" /></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file hash="b93c82493edf2dfe0b554b587c0eda53" name="turpentine_esi.xml" /></dir><dir name="template"><dir name="turpentine"><file hash="cab2b26a36c018e6a256572179b1b5d7" name="esi.phtml" /><file hash="1b337a1cbca5b87a77a3f2419a517d87" name="ajax.phtml" /></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file hash="58848d4d90973bfd63b466ea181352a5" name="Nexcessnet_Turpentine.xml" /></dir></target><target name="magecommunity"><dir name="Nexcessnet"><dir name="Turpentine"><dir name="controllers"><file hash="54df88dfc4538dad394d0f4fbe952846" name="EsiController.php" /><dir name="Varnish"><file hash="9295d4020c36b22265cb43ecf8db9f36" name="ManagementController.php" /></dir></dir><dir name="Helper"><file hash="f87ce32f57c8f790790ebd63d287bd2d" name="Debug.php" /><file hash="2e43a7433dabf0a628cdbeef039c3395" name="Varnish.php" /><file hash="2ee46966dc025c7bb18e35262bda7a0c" name="Esi.php" /><file hash="0175afdbf2b9358ba77f14fa66ed39b1" name="Data.php" /><file hash="61b69cb98039441a01207a1aae6131f0" name="Cron.php" /><file hash="8f0dd23f9a7b98d8254acf18b6750f1e" name="Ban.php" /></dir><dir name="Model"><file hash="492255f04ccd56e5cf9cce95b9384aee" name="Session.php" /><dir name="Observer"><file hash="9d57fad69ff42b71c66ca26bc3372317" name="Debug.php" /><file hash="d7e5901c0bc96e54685a3c9955fbe716" name="Varnish.php" /><file hash="ad6fcf6dccd784812825cd38039a4bbd" name="Esi.php" /><file hash="a34e79218e8ca1fefad303b9399bda9d" name="Cron.php" /><file hash="cae3420ba6b543eeba4a7a1c5427de50" name="Ban.php" /></dir><dir name="Config"><dir name="Select"><file hash="9348c5e58037fd97d89b84ccab4ef2d0" name="Toggle.php" /><file hash="dc472f34c25b1688cfa9fa206958c536" name="Version.php" /></dir></dir><dir name="Varnish"><file hash="fcb8a5582c6f920e910b417c671df6d2" name="Admin.php" /><dir name="Configurator"><file hash="970a058bf2a73a5774b004390fcfaa07" name="Version3.php" /><file hash="4fba0ac0b4837cabec5bbee428d229df" name="Version2.php" /><file hash="8075d99c4a59fffa37d733b7cd162ac6" name="Abstract.php" /></dir><dir name="Admin"><file hash="4399067515aaa22c8143148e891c92d2" name="Socket.php" /></dir></dir><dir name="Shim"><dir name="Mage"><dir name="Core"><file hash="821bff6c2fb372e3ffb39abf6453b3f8" name="Layout.php" /><file hash="5631df5e00de1fb5cbec5359457cb8bb" name="App.php" /></dir></dir></dir></dir><dir name="etc"><file hash="872e79b779e14ac50d5a3ab4d0e6a215" name="config.xml" /><file hash="029e85a1387af95129f400e43eefe422" name="system.xml" /></dir><dir name="misc"><file hash="f083d5fbf4634af60ed5bb257197834f" name="uuid.c" /><file hash="fcc5ba12f5a807446c0d59c2ade8fd01" name="version-2.vcl" /><file hash="c4ec1bdf152f701f288a176cc8657ebc" name="version-3.vcl" /></dir><dir name="Block"><file hash="e517426e31404fb710c821d46085700f" name="Management.php" /><dir name="Core"><file hash="b64177f637923dbb06b95cb2ca42b675" name="Messages.php" /></dir></dir><dir name="sql" /></dir></dir></target></contents><dependencies><required><php><min>5.2.13</min><max>6.0.0</max></php></required></dependencies><authors><author><name>Chris Wells</name><user>nexcess_net</user><email>clwells@nexcess.net</email></author><author><name>Alex Headley</name><user>aheadley_nex</user><email>aheadley@nexcess.net</email></author></authors><date>2013-03-06</date><compatibile /><channel>community</channel><description>Turpentine is a Magento extension to improve Magento's compatibility with Varnish, a very-fast caching reverse-proxy. By default, Varnish doesn't cache requests with cookies and Magento sends the frontend cookie with every request causing a (near) zero hit-rate for Varnish's cache. Turpentine provides Varnish configuration files (VCLs) to work with Magento and modifies Magento's behaviour to significantly improve the cache hit rate.</description></package>
1
+ <package><name>Nexcessnet_Turpentine</name><license uri="http://opensource.org/licenses/GPL-2.0">GPLv2</license><notes>Supports Magento v1.6 and later</notes><time>18:01:13</time><__packager>build_package.py v0.0.3</__packager><summary>Improves Magento support for Varnish caching and generates 2.1 and 3.0 compatible VCLs.</summary><stability>stable</stability><__commit_hash>b937ef3d23bba70d197d17b7a617db2ae81690c2</__commit_hash><version>0.5.2</version><extends /><contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file hash="a0bd4a5632b369b058c0ec5262e0cc49" name="turpentine.xml" /></dir><dir name="template"><dir name="turpentine"><file hash="b5cae58feecaec4b1c2e4558313c2a3f" name="varnish_management.phtml" /></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file hash="b93c82493edf2dfe0b554b587c0eda53" name="turpentine_esi.xml" /></dir><dir name="template"><dir name="turpentine"><file hash="4e3e5919b4eb862ac1f5e10a9bcea127" name="esi.phtml" /><file hash="1b337a1cbca5b87a77a3f2419a517d87" name="ajax.phtml" /></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file hash="58848d4d90973bfd63b466ea181352a5" name="Nexcessnet_Turpentine.xml" /></dir></target><target name="magecommunity"><dir name="Nexcessnet"><dir name="Turpentine"><dir name="controllers"><file hash="8013ce596f20d78973bc5f1876bc3a57" name="EsiController.php" /><dir name="Varnish"><file hash="9295d4020c36b22265cb43ecf8db9f36" name="ManagementController.php" /></dir></dir><dir name="Helper"><file hash="f87ce32f57c8f790790ebd63d287bd2d" name="Debug.php" /><file hash="2e43a7433dabf0a628cdbeef039c3395" name="Varnish.php" /><file hash="e91836f4e7967f026183cb5c87476775" name="Esi.php" /><file hash="77fffe4fc62f2e2bff62663182a47f06" name="Data.php" /><file hash="61b69cb98039441a01207a1aae6131f0" name="Cron.php" /><file hash="8f0dd23f9a7b98d8254acf18b6750f1e" name="Ban.php" /></dir><dir name="Model"><file hash="c2cb79001524617febbfddf099d09f37" name="Session.php" /><dir name="Observer"><file hash="9d57fad69ff42b71c66ca26bc3372317" name="Debug.php" /><file hash="d7e5901c0bc96e54685a3c9955fbe716" name="Varnish.php" /><file hash="1e05e2f8656afab31ed2d9e4fdf44737" name="Esi.php" /><file hash="a34e79218e8ca1fefad303b9399bda9d" name="Cron.php" /><file hash="7c164dc3b91790d513be1410f94f4071" name="Ban.php" /></dir><dir name="Config"><dir name="Select"><file hash="9348c5e58037fd97d89b84ccab4ef2d0" name="Toggle.php" /><file hash="dc472f34c25b1688cfa9fa206958c536" name="Version.php" /></dir></dir><dir name="Varnish"><file hash="fcb8a5582c6f920e910b417c671df6d2" name="Admin.php" /><dir name="Configurator"><file hash="970a058bf2a73a5774b004390fcfaa07" name="Version3.php" /><file hash="4fba0ac0b4837cabec5bbee428d229df" name="Version2.php" /><file hash="8075d99c4a59fffa37d733b7cd162ac6" name="Abstract.php" /></dir><dir name="Admin"><file hash="4399067515aaa22c8143148e891c92d2" name="Socket.php" /></dir></dir><dir name="Shim"><dir name="Mage"><dir name="Core"><file hash="821bff6c2fb372e3ffb39abf6453b3f8" name="Layout.php" /><file hash="5631df5e00de1fb5cbec5359457cb8bb" name="App.php" /></dir></dir></dir></dir><dir name="etc"><file hash="a963731e83c6e2cb440bf0c437a703da" name="config.xml" /><file hash="029e85a1387af95129f400e43eefe422" name="system.xml" /></dir><dir name="misc"><file hash="f083d5fbf4634af60ed5bb257197834f" name="uuid.c" /><file hash="adc3b270f3f708c04aa1a09a9e1a1494" name="version-2.vcl" /><file hash="3fcffc168124a1e93b942fef40af4e9c" name="version-3.vcl" /></dir><dir name="Block"><file hash="e517426e31404fb710c821d46085700f" name="Management.php" /><dir name="Core"><file hash="b64177f637923dbb06b95cb2ca42b675" name="Messages.php" /></dir></dir><dir name="sql" /></dir></dir></target></contents><dependencies><required><php><min>5.2.13</min><max>6.0.0</max></php></required></dependencies><authors><author><name>Chris Wells</name><user>nexcess_net</user><email>clwells@nexcess.net</email></author><author><name>Alex Headley</name><user>aheadley_nex</user><email>aheadley@nexcess.net</email></author></authors><date>2013-03-21</date><compatibile /><channel>community</channel><description>Turpentine is a Magento extension to improve Magento's compatibility with Varnish, a very-fast caching reverse-proxy. By default, Varnish doesn't cache requests with cookies and Magento sends the frontend cookie with every request causing a (near) zero hit-rate for Varnish's cache. Turpentine provides Varnish configuration files (VCLs) to work with Magento and modifies Magento's behaviour to significantly improve the cache hit rate.</description></package>