steveosoule
8/6/2016 - 12:12 AM

Miva - Use Transient Module to Cache Entire Store

Miva - Use Transient Module to Cache Entire Store

<mvt:assign name="g.Transient_Code" value="'Screen__' $ g.Proxy_Screen" />
<mvt:if expr="g.Secure">
	<mvt:assign name="g.Call_URL" value="g.domain:mm_surl $ 'Screen=' $ g.Proxy_Screen" />
<mvt:else>
	<mvt:assign name="g.Call_URL" value="g.domain:mm_url $ 'Screen=' $ g.Proxy_Screen" />
</mvt:if>

<mvt:if expr="g.Proxy_Screen EQ 'CTGY' ">
	<mvt:assign name="g.Transient_Code" value="g.Transient_Code $ '--' $ g.Category_Code" />
	<mvt:assign name="g.Call_URL" value="g.Call_URL $ '&Category_Code=' $ g.Category_Code" />
<mvt:elseif expr="g.Proxy_Screen EQ 'PROD' ">
	<mvt:assign name="g.Transient_Code" value="g.Transient_Code $ '--' $ g.Product_Code" />
	<mvt:assign name="g.Call_URL" value="g.Call_URL $ '&Product_Code=' $ g.Product_Code" />
</mvt:if>

<mvt:do file="g.Module_Root $ '/modules/util/transients.mvc'" name="l.settings:transient_data" value="Get_Transient( g.Transient_Code )" />

<mvt:if expr="l.settings:transient_data EQ 0">
	<mvt:assign name="l.settings:transient_data" value="''" />

	<mvt:call action="g.Call_URL" method="'GET'">
		<mvt:assign name="l.settings:transient_data" value="l.settings:transient_data $ s.callvalue" />
	</mvt:call>

	<mvt:assign name="l.settings:transient_data" value="l.settings:transient_data $ '<!-- !@! Served from Transient Cache | ' $ g.Call_URL $ ' | Cached on ' $ s.dyn_stm_wday $ ' ' $ s.dyn_stm_mon $ ' ' $ s.dyn_tm_mday $ ', ' $ s.dyn_tm_year $ ' ' $ s.dyn_tm_hour $ ':' $ s.dyn_tm_min $ ':' $ s.dyn_tm_sec $ ' ' $ s.dyn_stm_zone $ ' -->'" />

	<mvt:do file="g.Module_Root $ '/modules/util/transients.mvc'" name="l.set_transient" value="Set_Transient( g.Transient_Code, trim(l.settings:transient_data), 60*60*24)" />
</mvt:if>

&mvt:transient_data;

Miva - Use Transient Module to Cache Entire Store (prototype)

The following code is a basic prototype of how the main landing pages could be cached using the Transient module and some .htaccess rules.

So far it only would work well with Miva's Long Merchant URLs or the Legacy SEO Short Link structure. I haven't tried finding a way to get it to work with URI Management yet.

This implimentation is not complete, and would require some other updates:

  • Remove Session IDs from the cached HTML
  • Use to AJAX load in mini-basket & account info
  • Needs to account for query string parameters, POST's, and other more intricate web-requests
  • Add a way for store-owner to purge the cache manually.
  • Test this thouroughly!
# Product Pages
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^p/([^/.]+)$ /mm5/merchant.mvc?Screen=cache_layer&Proxy_Screen=PROD&Product_Code=$1 [L,NC]

# Category pages
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^c/([^/.]+)$ /mm5/merchant.mvc?Screen=cache_layer&Proxy_Screen=CTGY&Category_Code=$1 [L,NC]

# Static Pages
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^cs/([^/.]+)$ /mm5/merchant.mvc?Screen=cache_layer&Proxy_Screen=$1 [L,NC]

# Home page
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^$ /mm5/merchant.mvc?Screen=cache_layer&Proxy_Screen=SFNT [L,NC]