2

I am using fragment caching in most places with Stash to cache the data from ExpressionEngine on my current project, but there are a few instances where pages are totally static, such as the about page. There is nothing dynamic at all going on with it, and therefore nothing that needs to be escaped from caching.

It seems I could just as easily use either {exp:stash:static} as {exp:stash:cache}. I set up the template with {exp:stash:cache} and I now see it sitting the db as a fully cached flat file. If I were to use {exp:stash:static}, then it would do the same thing but write it as a file to the specified directory instead of the database, I guess.

So my question is, for instances like this when there is no content that needs to be escaped from the cache, is one method significantly more performant than the other? I'd assume using the static cache is more performant as then there is no call to the database, but I'd appreciate some views on this before choosing it as my preferred method. Thank you!

4

{exp:stash:static} caches the entire page to a static file. The cached output is not stored in the database. And you can't cache just a region / section of the page.

When it works for you to use {exp:stash:static}, it should return pages noticeably faster than {exp:stash:cache}, and also (since the page requests route directly to the static file, without touching EE) put less load on your server memory.

{exp:stash:cache} caches either the entire page, or a region / section of the page. And the cache is stored in the database. Requests to {exp:stash:cache} do route through EE, but all of the processing that normally would occur (i.e., whatever you have inside the {exp:stash:cache} tag pair) is replaced by a shortcut / fast call to the database to get the results.

For comparison, if you're familiar with CE Cache, {exp:stash:static} is like CE Cache's static page caching--the {exp:ce_cache:stat:ic} tag, and {exp:stash:cache} is like CE Cache's database-backed caching--the {exp:ce_cache:it drivers="db"}{exp:ce_cache:it} tag pair.

(caveat: I'm still getting the hang of using Stash, so this is more from studying the documentation and a small number of experiments, than from production experience. I do have a lot of production experience with CE Cache and Solspace's Static Page Caching, however.)

| improve this answer | |
  • 2
    This is nearly right. {exp:stash:static} stores the cached page in the database AND as a static file. Editing or deleting the database cache in Mustash will update / delete the corresponding static file. EE and PHP are bypassed entirely when rendering the static cached page. It is equivalent to serving a static html file. A database version is stored as well so that it is possible to update and manage the static cache via Mustash cache-breaking rules, and to enable progressive cache rebuilds when caches cleared. speakerdeck.com/croxton/stash-development-strategies?slide=38 – Mark Croxton Nov 18 '13 at 9:53
1

That's my understanding too. But rather than me trying to explain why, I think you'd be best contacting Nexcess to ask them to send you a copy of their ExpressionEngine – Caching, and Best Practices for Performance PDF they released after their presentation at the recent EECI Conference as it goes into great detail about the different caching methods available to ExpressionEngine.

It doesn't discuss Stash directly but it does talk about db v static caching in relation to CE Cache by Causing Effect (as well as other methods) and the differences/similarities would be pretty much the same I'd imagine.

They tweeted about it shortly after the conference with a link to download the file, but it didn't work for me so they asked me to email them and then emailed it back.

It's definitely worth the effort to get hold of.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.