0

What do I have to do to get files into the /static_cache/-folder so I can use the {exp:stash:cache}-tag.

I have yet again been iterating through the new stash-docs over and over but I cant figure it out.

I am pretty sure I got the prefs-files right but a little unsure on configuring the htaccess-file. Do I change anything else than the domain and the path of the static_cache-file?

/David

5

Files are written to the static cache directory by Stash - you don't put files in there. Typically these cached files would be your fully rendered HTML pages. This is the opposite of the stash template directory, where you add template files (containing EE tags, variables etc.) which are read by Stash.

After creating a folder called 'static_cache' (or whatever pleases you) in your public webroot, you need to customise the .htaccess file with three values:

  • The path to your stash_cache directory
  • The URL to your stash_cache directory
  • The site_id of your site. If you are NOT using the Multiple Site Manager then the site_id will always have a value of 1.

Let's say your path is /home/mysite/public_html/static_cache/, your relative url is /static_cache (you could use an absolute url instead if you prefer) and your site_id is 1. Your file would look like this:

    RewriteEngine on    

    #################################################################################
    # START STASH STATIC CACHE

    # Exclude POST requests
    RewriteCond %{REQUEST_METHOD} !=POST

    # Exclude CSS/ACT EE URLs
    RewriteCond %{QUERY_STRING} !^(css|ACT|URL)

    # Remove index.php from conditions
    RewriteCond $1 ^(index.php/)*(.*)(/*)$

    # Check if cached index.html exists
    RewriteCond /home/mysite/public_html/static_cache/1/$2/index.html (.*\.(.*))$
    RewriteCond %1 -f

    # Rewrite to the cached page
    RewriteRule ^(index.php/*)*(.*)(/*) /static_cache/1/$2/index.%2 [L]

    # END STASH STATIC CACHE RULES
    #################################################################################

    # -------------------------------------------------------------------------------
    # Officially supported method to remove index.php from ExpressionEngine URLs
    # See: http://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html
    # -------------------------------------------------------------------------------

    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

    </IfModule>

Now to actually use static caching you can use the {exp:stash:static} tag, the {exp:stash:cache} with process="static" or the {stash:embed} with process="static".

3
  • Ah thanks! I was really unsure if I should change [site_id] for a number or not. Do I use {exp:stash:static} as a tagpair when to cache a complete template? – David S Jul 1 '13 at 13:12
  • 1
    {exp:stash:static} is a single tag - you can put it anywhere in your template, but only use it once. – Mark Croxton Jul 2 '13 at 9:16
  • Wooohooo!!! its FAST!!! it so fast I might need a change! :D. (what took me so long was figuring out dots and slashes on my local install). Oh I'm a happy dude right now! – David S Jul 2 '13 at 13:41

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.