-
Notifications
You must be signed in to change notification settings - Fork 20
Cache pruning configuration
Cache pruning is the process whereby variables that have expired are removed from the cache.
Stash provides a number of configuration options that affect pruning. Calculating the correct values for these is important to "even out" events that affect the cache so that they occur over an extended period of time instead of all at once.
By default Stash uses a "poor man's cron" to trigger cache pruning periodically. As users browse your website and request pages, Stash effectively rolls a dice to see whether a particular request should trigger pruning. How likely that pruning is triggered by a request is determined by the stash_prune_probability
value.
To calculate prune probability, first find out roughly how many pages your site serves over a given interval. Google Analytics is a good place to start for this data, but bear in mind that robots/crawlers may make up to 50% or more of your traffic and are not reflected in the Analytics reports.
Now decide how often pruning should be triggered. Somewhere between 5 - 15 minutes would be suitable for most websites.
Then use this formula to calculate the probability:
m = measured time period in seconds, e.g. 600 (10 minutes)
i = desired interval between pruning in seconds, e.g. 300 (5 minutes)
p = page views recorded in m seconds
stash_prune_probability = ((m/i) / p) * 100
Page views measured over 10 minutes, and we want a 5 minute pruning interval:
~50,000 page views (500 concurrent users)
stash_prune_probability: 0.004
~25,000 page views (250 concurrent users)
stash_prune_probability: 0.008
~5000 page views (50 concurrent users)
stash_prune_probability: 0.04
~2,500 page views (25 concurrent users)
stash_prune_probability: 0.01333
~1,250 page views (12 concurrent users)
stash_prune_probability: 0.16
~500 page views (5 concurrent users)
stash_prune_probability: 0.4
~250 page views (2 concurrent users)
stash_prune_probability: 0.8
Mustash users can setup a CRON or scheduled task to prune the cache periodically
Your crontab line would look something like this, to trigger the pruning script every 5 minutes:
*/5 * * * * wget -qO- 'http://my_website.com/?ACT=123&key=456&prune=1' >/dev/null 2>&1
When using an external CRON, be sure to disable Stash's default "poor man's cron":
$assign_to_config['stash_prune_enabled'] = FALSE;
The stash_invalidation_period
determines the specific time period over which a selection of variables are pruned from the cache, when cache-breaking is triggered. Instead of being deleted immediately, the selected variables are given staggered expiry times which are distributed within the invalidation period, with the time offset corresponding approximately to each variable's initial creation date; this has the effect that older variables expire and rebuild earlier, maintaining the same order in which the variables were first created.
The stash_invalidation_period
applies to variables deleted with the {exp:stash:delete}
tag, variables targeted by cache-breaking rules in Mustash and variables deleted using the Stash::destroy()
method in other custom extensions.
Setting stash_invalidation_period
to 0 disables invalidation, and variables will be deleted immediately. This is the recommended value for most situations.
If you make use of static caching, this value should usually be 0, as static html files must be deleted immediately regardless of the value of stash_invalidation_period
. And/or, if your content editors like to see their changes reflected immediately, you will need to set the value to 0.
Otherwise, busy sites may benefit from setting this value to at around 6x the pruning interval. For example, if you have calculated the stash_prune_probability
based on a prune interval of 300 seconds, then set stash_invalidation_period
to 1800 seconds. This would mean that after editing an entry it would take up to 30 minutes for the changes to apply to the live site.
Getting started
Using Stash
Using Mustash
- Mustash
- Installing Mustash
- Managing variables
- Managing bundles
- Cache-breaking rules
- Mustash plugins
- Mustash Varnish plugin
- Mustash plugin development
- Mustash API
Template design patterns
Tag reference
- {exp:stash:set}
- {exp:stash:get}
- {exp:stash:block}
- {exp:stash:set_value}
- {exp:stash:append}
- {exp:stash:append_value}
- {exp:stash:prepend}
- {exp:stash:prepend_value}
- {exp:stash:copy}
- {exp:stash:context}
- {exp:stash:is_empty}
- {exp:stash:not_empty}
- {exp:stash:set_list}
- {exp:stash:get_list}
- {exp:stash:append_list}
- {exp:stash:prepend_list}
- {exp:stash:split_list}
- {exp:stash:join_lists}
- {exp:stash:list_count}
- {exp:stash:unset}
- {exp:stash:flush_cache}
- {exp:stash:bundle}
- {stash:embed}
- {exp:stash:extend}
- {exp:stash:parse}
- {exp:stash:cache}
- {exp:stash:static}
- {exp:stash:finish}
- {exp:stash:not_found}
- Short tag syntax
- Using Stash methods in your own add-ons