Cache URL Plugin¶
注解
This plugin is deprecated as of v6.2.0 and will be removed as of v7.0.0. It is replaced by a new Cache Key Manipulation Plugin and you should change your configurations to use the new plugin instead. Please find some examples below.
This plugin allows you to change the cache key that is used for caching a request by using any portion of the URL via regular expressions.
Purpose¶
By default Traffic Server generates keys for cache objects from the full request URL. Future requests will only be able to use the existing cache object if they result in the same cache key. It can be the case, however, that the same content is accessible through more than one request URL. Without any special configuration, that same content will result in multiple cache objects based on the differing URLs.
In this scenario, it can be very beneficial to allow Traffic Server to reuse a cache object for multiple URLs. This plugin enables that behavior, by allowing the administrator to define custom patterns for generating cache keys for some, or all, of their site’s URLs. Uninteresting or irrelevant portions of request URLs may be removed, or altered, before the cache key is created using the full power of regular expressions.
Installation¶
This plugin is considered stable and is included with Traffic Server by default. There are no special steps necessary for its installation.
Configuration¶
Enable the plugin by modifying
plugin.configto include the plugin:cacheurl.so
Create a
cacheurl.configfile in the plugin directory with the url regex patterns you wish to match, using the following format:<pattern> <replacement>
The
<pattern>is a regular expression (PCRE) applied against the incoming request URL. The<replacement>may contain$1,$2, and so on, which will be replaced with the appropriate matching group from<pattern>.Reload your Traffic Server configuration with
traffic_ctl config reload.
Logging¶
A new log file will be generated by this plugin, containing entries for each
incident of an incoming URL’s cache key being altered, located in the Traffic Server
log directory and named cacheurl.log.
Examples¶
While many possibilities exist, limited really only by your site’s URL scheme and the capabililties of PCRE regular expressions, the following are examples of a few situations Traffic Server administrators may encounter.
Multiple Domains, One Cache Object¶
If you have multiple subdomains which serve the same file content, there may be no reason to duplicate their storage (leading to higher churn and faster potential eviction of still-fresh objects) in your Traffic Server cache. By default, however, the differing subdomains will lead to differing cache keys. To work around this, a pattern like the following can be used to create a single cache key which will be valid for all subdomains:
http://s[123].example.com/(.*) http://s.example.com.TSINTERNAL/$1
Now, the domains s1.example.com, s2.example.com, and s3.example.com
will effectively share cache objects. Adding a unique suffix (TSINTERNAL in
this example) to the cache key guarantees that it won’t clash with a real URL
should s.example.com exist.
Converting to Cache Key Manipulation Plugin¶
You could do the same with Cache Key Manipulation Plugin by adding the following to the mapping rules:
@plugin=cachekey.so @pparam=--capture-prefix=/s[123].example.com:.*/s.example.com.TSINTERNAL/
Ignoring Some Query Parameters¶
If your site attaches, for example, session information to URLs, even on pages which do not include session-specific content and may be safely cached, you can add a pattern which strips this unnecessary information from the URL before generating a cache key, while still retaining important query parameters:
http://www.example.com/video\?.*?\&?(id=[0-9a-f]*).*?\&(format=[a-z]*) http://video-srv.example.com.ATSINTERNAL/$1&$2
Converting to Cache Key Manipulation Plugin¶
You could do the same with Cache Key Manipulation Plugin by adding the following to the mapping rules:
@plugin=cachekey.so @pparam=--include-params=id,format
Ignore Query String on Specific Pages¶
To completely ignore a query string for a specific page, it’s quite easy to
simply match and drop everything from the ? query string opener to the end
of the URL:
http://www.example.com/some/page(?:\?|$) http://www.example.com/some/page
Converting to Cache Key Manipulation Plugin¶
You could do the same with Cache Key Manipulation Plugin by adding the following to the mapping rules:
@plugin=cachekey.so @pparam=--remove-all-params