Extension, Module

Archived
Forum
(read-only)

Stash

ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4, ExpressionEngine 5, ExpressionEngine 6

Back to this add-on's main page
View Other Add-ons From Mark Croxton

     

Wrapping template in stash:cache returns same page throughout site

Support Request

digitalDesigns
digitalDesigns

We are wrapping up a site build and as one of the final steps we always wrap our templates in exp:stash:cache to speed up load time. After implementing this on two templates on this site, I found that the first template was cached correctly (visible in Mustash) but after it was cached every subsequent page that was visited displayed that template.

The simplified code we are using looks like this:

{exp:stash:cache bundle="templates" refresh="60"}
{stash
:embed file_name="default"}
{exp
:stash:set name="content"}
CONTENT OF PAGE HERE
{
/exp:stash:set}
{
/exp:stash:cache} 

The wrapper template (default.html) contains the header and footer and calls the

{exp:stash:get name="content"

content in the middle

This is something we have done on every site we have recently built and never had this problem before. What are we missing, or what is different about this site? EE version 6.5.6

digitalDesigns
# 1
digitalDesigns

Does anyone have any information about what could be causing this? Thanks!

Mark Croxton
# 2
Developer
Mark Croxton

Do you mean EE version 3.5.6?

Make sure you have this in your config:

$config[‘uri_protocol’] = ‘AUTO’;

I’m not sure this is your issue, but on recent Apache 2.4.x servers you will need to use the question mark in your htaccess rewrite:

RewriteRule ^(.*)$ /index.php?/$1 [L] 

Other than that, what’s the url of the page that is cached?

 

 

 

digitalDesigns
# 3
digitalDesigns

Sorry, yes 3.5.6

I added this to the config (it wasnt in there) $config[‘uri_protocol’] = ‘AUTO’;
I also added the question mark to the rewrite rule but still getting the same results. Only the first cached page is displaying:

Mustash shows this as the index page URI [index]:cache

digitalDesigns
# 4
digitalDesigns

We are also using resource router to reroute several templates to achieve the URL structure we want. Could this be impacting the way stash works?

Mark Croxton
# 5
Developer
Mark Croxton

Hi

Stash will go and get the actual url regardless of any other addon affecting routing so you should get a unique cached variable created for every unique and addressable url. See here for URL planning:

https://github.com/croxton/Stash/wiki/Caching#carefully-plan-your-url-scheme

Whatever you do with Resource Router would not affect this, Stash should always use the URL you see in your browser.  And I know that this works as expected in 3.5.6 as we also have several projects using with Resosurce Router with that version of EE.

So something else might be going on here but it’s very hard to say what it is :/ You will need to try to debug what is happening.

Try setting up some test templates with minimal content to establish if that works (checklit generates a variable with the correct url when you look at Mustash), then clear cache, add in tags and try again until until it stops working. That would help establish if there is an add-on conflict.

You could also try disabling other third-party add-on extensions to see if there is a conflict there.

Last idea - something as simple as missing closing tag could cause this.

Let me know how you get on.

 

digitalDesigns
# 6
digitalDesigns

Thanks - I did some testing today and removed ALL EE code - just static HTML and it still did the same thing. Mustash only collects and stores the first URL but any subsequent URL’s don’t show up in Mustash. This test confirms that it isn’t an add-on conflict or a closing tag missing, correct?

The URL that mustash captures is test/view:cache

Below is the code from our config - wondering if there might be something wrong here (I removed the specific basepaths)

$config['stash_file_basepath''/path/hidden';
 
$config['stash_file_sync'FALSE// set to TRUE to sync stash embed file changes during development
 
$config['stash_file_extensions'= array('html''md''css''js''rss''xml');
 
$config['stash_static_basepath''/path/hidden';
 
$config['stash_static_url''/static_cache/'// should be a relative url
 
$config['uri_protocol'AUTO;
 
$config['stash_static_cache_enabled'TRUE// set to TRUE to enable static caching
 
$config['stash_static_cache_index'TRUE// set to TRUE to use Stash as an index only when static caching (variable value not saved)
 
$config['stash_static_character_blacklist'= array('{''}''<''>'':''"''\\''|''*''.');
 
$config['stash_query_strings'FALSE// set to TRUE to cache query strings when referencing the current uri with @URI
 
$config['stash_cookie''stashid'// the stash cookie name
 
$config['stash_cookie_expire'0// seconds - 0 means expire at end of session
 
$config['stash_cookie_enabled'TRUE// set to FALSE if not using 'user' scope and cache pruning is disabled
 
$config['stash_default_scope''local'// default variable scope if not specified
 
$config['stash_default_refresh'0// default cache refresh period in minutes
 
$config['stash_limit_bots'FALSE// stop database writes by bots to reduce load on busy sites
 
$config['stash_bots'= array('bot''crawl''spider''archive''search''java''yahoo''teoma');
 
$config['stash_prune_enabled'TRUE// set FALSE if you trigger pruning with a CRON/scheduled task (via Mustash API)
 
$config['stash_prune_probability'4;  // % chance that a request initiates cache pruning
 
$config['stash_invalidation_period']  0;  // duration of cache invalidation in seconds
 
$config['stash_parse_if_in']  FALSE;  // enable parsing of {if var IN (1|2|3)...{/if} style conditionals in Stash templates
 # $config['stash_var_prefix'] = 'preview-'; // apply a prefix to all saved variables, useful for entry previews



$config['resource_router'= array(
  
'things-to-do/:url_title' => 'things-to-do/view',
  
'things-to-do/:pagination' => 'things-to-do/pagination',
  
'places-to-stay/:url_title' => 'places-to-stay/view',
  
'places-to-stay/:category_url_title' => 'places-to-stay/category',
  
'food-drink/:category_url_title' => 'food-drink/category',
  
'food-drink/:category_url_title/:category_url_title' => 'food-drink/food-type-category',
  
'food-drink/:url_title' => 'food-drink/view',
  
'events/:url_title' => 'events/view',
  
'events/:category_url_title' => 'events/category',
  
'blog/:url_title' => 'blog/view',
  
'blog/:category_url_title' => 'blog/category',
); 

 

Mark Croxton
# 7
Developer
Mark Croxton

Please check the ID column of your exp_stash table. It should be set to AUTO_INCREMENT - I’m betting it isn’t. Maybe you copied the db structure over manually?

You can uninstall / reinstall Stash to get it to recreate the tables if you prefer.

digitalDesigns
# 8
digitalDesigns

I looked at the exp_stash table and it is set to AUTO_INCREMENT. I also updated a couple modules that had recently been updated just in case that could be the issue. I then went back and visited the test template group (the only templates that are currently wrapped in {exp:stash:cache bundle=“templates” refresh=“60”}{/exp:stash:cache})

Mustash captures the URL successfully but the code saved is the same for every template it captures, and then it displays the same page no matter what link is clicked on.

What else can we try?

Mark Croxton
# 9
Developer
Mark Croxton

You could try disabling any other extensions used by third party add-ons.

Other than that, set up a fresh EE install on the same server and see if you can reproduce the issue with only Stash + Mustash installed. Make sure you use a default config for EE, not your site’s custom config. And add the stash config values as per the wiki. If you still have the issue then it must be environmental - something related to the server, if not then it must be config related.