CACHE.CONFIG(5) | Apache Traffic Server | CACHE.CONFIG(5) |
cache.config - the cache.config file allows you to overrule the origin's cache policies. You can add caching rules to specify the following:
IMPORTANT:
After modifying cache.config, run traffic_ctl config reload to apply changes.
Each line in the cache.config file contains a caching rule. Traffic Server recognizes three space-delimited tags:
primary_destination=value secondary_specifier=value action=value
You can use more than one secondary specifier in a rule. However, you cannot repeat a secondary specifier. The following list shows the possible primary destinations with allowed values.
The primary destination field on each line is used to restrict the requests to which the caching rule will apply.
The secondary specifiers are optional and may be used to further restrict which requests are impacted by the caching rule. Multiple secondary specifiers may be used within a single rule, though each type of specifier can appear at most one time. In other words, you may have both a port and scheme in the same rule, but you may not have two ports.
The final component of a caching rule is the action, which determines what Traffic Server will do with all objects matching the primary destinations and secondary specifiers of the rule in question.
Value | Effect |
never-cache | Never cache specified objects, it will be overwritten by ttl-in-cache. |
ignore-no-cache | Ignore all Cache-Control: no-cache headers. |
ignore-client-no-cache | Ignore Cache-Control: no-cache headers from client requests. |
ignore-server-no-cache | Ignore Cache-Control: no-cache headers from origin server responses. |
The value is the amount of time you want to keep the object(s) in the cache. The following time formats are allowed:
When multiple rules are specified in cache.config, Traffic Server will check all of them in order for each request. Thus, two rules which match the same request but have conflicting actions will result in their actions being compounded. In other words, Traffic Server does not stop on the first match.
In some cases, this may lead to confusing behavior. For example, consider the following two rules:
dest_domain=example.com prefix=foo suffix=js revalidate=7d dest_domain=example.com suffix=js action=never-cache
Reading that under the assumption that Traffic Server stops on the first match might lead one to assume that all Javascript files will be excluded from the Traffic Server cache, except for those whose paths begin with foo. This, however, is not correct. Instead, the first rule establishes that all Javascript files with the path prefix foo will be forced to revalidate every seven days, and then the second rule also sets an action on all Javascript files, regardless of their path prefix, to never be cached at all. Because none of the Javascript files will be cached at all, the first rule is effectively voided.
A similar example, but at least one with a correct solution, might be an attempt to set differing values for the same action, as so:
# Incorrect! dest_domain=example.com prefix=foo suffix=js revalidate=7d dest_domain=example.com suffix=js revalidate=1d # Correct! dest_domain=example.com suffix=js revalidate=1d dest_domain=example.com prefix=foo suffix=js revalidate=7d
The latter accomplishes the implied goal of having a default, or global, timer for cache object revalidations on Javascript files, as well as a more targeted (and longer) revalidation time on just those Javascript files with a particular prefix. The former fails at this goal, because the second rule will match all Javascript files and will override any previous revalidate values that may have been set by prior rules.
When multiple rules are matched in the same request, never-cache will always be overwritten by ttl-in-cache. For example:
# ttl-in-cache=1d never-cache=false dest_domain=example.com action=never-cache dest_domain=example.com ttl-in-cache=1d
The following example configures Traffic Server to revalidate gif and jpeg objects in the domain mydomain.com every 6 hours, and all other objects in mydomain.com every hour. The rules are applied in the order listed.
dest_domain=mydomain.com revalidate=1h dest_domain=mydomain.com suffix=gif revalidate=6h dest_domain=mydomain.com suffix=jpeg revalidate=6h
Force a specific regex to be in cache between 7-11pm of the server's time for 26 hours.
url_regex=example.com/articles/popular.* time=19:00-23:00 ttl-in-cache=1d2h
Prevent objects from being evicted from cache:
url_regex=example.com/game/.* pin-in-cache=1h
2023, dev@trafficserver.apache.org
November 2, 2023 | 9.2 |