Skip to content

{exp:stash:cache}

Mark Croxton edited this page Aug 8, 2013 · 28 revisions

Cache the rendered output of an entire page, or an arbitrary region of a template. This will create a variable cached in the database linked to the current page URI - therefore, use this tag for URI-specific data rather than caching items that are used on every page.

Note that this tag will not cache standard embeds (use stash embeds instead).

{exp:stash:cache bundle="my_blog"}

    {!-- this will be cached --}
    {exp:channel:entries channel="blog"}
        {title}
    {/exp:channel:entries}

    {!-- this will be escaped --}
    {stash:nocache}
        {exp:channel:entries channel="news"}
            {title}
        {/exp:channel:entries}
    {/stash:nocache}

{/exp:stash:cache}

Parameters

name = [ string ]

The name of your cached variable (optional). If you are using multiple cache tags in the same template, you must set a unique name for each.

bundle = [ string ]

The bundle to assign the cached variable to (optional, default is 'template'). Bundles are categories that you can use to group and organize your cached variables.

context = [ string ]

Define a context for your cached variable (optional). This is essentially a prefix for the name. Use to 'tag' your variables, in order to use as a target for cache-breaking.

refresh = [ int ]

The number of minutes to store the cached variable (optional, default is 0 - never)

replace = [ yes | no ]

Do you want the cached variable to be overwritten if it already exists? (optional, default is 'no')

parse_depth = [ int ]

How many passes of the template to make by the parser? (optional, default is 4)

process = [ end | static ]

When in the parse order of your EE template do you want the cache to be created? (optional, default is 'end')

process="end"

Cache is created at the end of template parsing after other tags and variables have been parsed.

process="static"

Cache the tagdata wrapped by the tag as a static file. Note that this only makes sense if the cache tag wraps the entire content of the template, since only the tags inside it will be saved to the static file.

parse_stage = [ set | get | both ]

When to parse the tagdata enclosed by the cache tag: parse and cache, or cache then parsed on retrieval, or do both (default="both").

parse_stage="set"

Parse the template the first time it is read, and cache the rendered result. Subsequent retrievals will return the cached template from the database without parsing the original content (unless replace="yes").

parse_stage="get"

Cache the tagdata without parsing it. When output to the template on the first and subsequent retrievals the template will be parsed. Note that this option is disabled when processing the cache as a static file (process="static")

parse_stage="both"

Parse the tagdata before caching AND after it is retrieved. This can be very useful when enclosing regions of your template with {stash:nocache}{/stash:nocache}. On SET the template code inside {stash:nocache} will not be parsed, but everything else will. On GET it will be parsed. This provides a way to partially cache some of your template code while leaving other areas dynamic. Note that this option is disabled when processing the cache as a static file (process="static")

Clone this wiki locally