trafficserver-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gancho Tenev <gan...@apache.org>
Subject Re: How can I set partial value of a query parameter into cache key?
Date Tue, 26 Jun 2018 06:27:24 GMT
Hello Chunlin,

There are examples of how to migrate from cacheurl.so to cachekey.so here (please note the
version is 7.1.x):
    https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/plugins/cachekey.en.html#cacheurl-plugin-to-cachekey-plugin-migration

I am not familiar with the exact requirements, i.e. the desired cache key or the exact regex/capture
definition used by your cacheurl configuration but here is an example below.
You could experiment with various combinations of cachekey parameters, regexes and replacement
strings (enable ATS log or XDebug plugin as described in the doc). The following is just an
example to demo the idea.

Let us say you would like to capture the everything before ‘?' and the query parameter ‘geo'
with the first 3 comma-separated elements from its values. 

Add a remap rule with a cachekey parameter to 
capture part of the whole URI as a prefix (http://example-cdn.com/pathfile <http://example-cdn.com/pathfile>)
and then 
capture part of the whole URI as a path (geo=country,state,city)
remove all query parameters and 
use an empty string as a cachekey element separator (you could leave it to its default ‘/‘
as well).


map http://example-cdn.com http://example.com:8888 \
  @plugin=cachekey.so \
    @pparam=--capture-prefix-uri=/([^\?]*)?/$1/ \
    @pparam=--capture-path-uri=/.*(geo=[^,]+,[^,]+,[^,]+)/?$1/ \
    @pparam=--remove-all-params=true \
    @pparam=--separator=


Now if you hit with:

curl -v -x localhost:8080 'http://example-cdn.com/path/file?kw=test&geo=country,state,city,street’

You would end up with the following ATS log:

$ ./bin/traffic_server -T cachekey
traffic_server: using root directory '/Users/gtenev/works/ats_dev/apache/run/trafficserver'
[Jun 25 23:05:21.829] Server {0x7fffb72f1380} DIAG: (cachekey) experimental/cachekey/configs.cc:365:init()
processing --capture-prefix-uri=/([^\?]*)?/$1/
[Jun 25 23:05:21.829] Server {0x7fffb72f1380} DIAG: (cachekey) experimental/cachekey/pattern.cc:334:compile()
compiling pattern:'([^\?]*)?', replace: true, replacement:'$1'
[Jun 25 23:05:21.829] Server {0x7fffb72f1380} DIAG: (cachekey) experimental/cachekey/configs.cc:365:init()
processing --capture-path-uri=/.*(geo=[^,]+,[^,]+,[^,]+)/?$1/
[Jun 25 23:05:21.829] Server {0x7fffb72f1380} DIAG: (cachekey) experimental/cachekey/pattern.cc:334:compile()
compiling pattern:'.*(geo=[^,]+,[^,]+,[^,]+)', replace: true, replacement:'?$1'
[Jun 25 23:05:21.829] Server {0x7fffb72f1380} DIAG: (cachekey) experimental/cachekey/configs.cc:365:init()
processing --remove-all-params=true
[Jun 25 23:05:21.829] Server {0x7fffb72f1380} DIAG: (cachekey) experimental/cachekey/configs.cc:365:init()
processing --separator=
[Jun 25 23:05:24.905] Server {0xb0016000} DIAG: (cachekey) experimental/cachekey/pattern.cc:277:replace()
replacing:'$1' in pattern:'([^\?]*)?', subject:'http://example-cdn.com/path/file?kw=test&geo=country,state,city,street'
[Jun 25 23:05:24.905] Server {0xb0016000} DIAG: (cachekey) experimental/cachekey/pattern.cc:308:replace()
replacing '$1' with 'http://example-cdn.com/path/file'
[Jun 25 23:05:24.905] Server {0xb0016000} DIAG: (cachekey) experimental/cachekey/pattern.cc:318:replace()
replacing '$1' resulted in 'http://example-cdn.com/path/file'
[Jun 25 23:05:24.905] Server {0xb0016000} DIAG: (cachekey) experimental/cachekey/cachekey.cc:305:appendPrefix()
added URI capture prefix, key: 'http://example-cdn.com/path/file'
[Jun 25 23:05:24.905] Server {0xb0016000} DIAG: (cachekey) experimental/cachekey/pattern.cc:277:replace()
replacing:'?$1' in pattern:'.*(geo=[^,]+,[^,]+,[^,]+)', subject:'http://example-cdn.com/path/file?kw=test&geo=country,state,city,street'
[Jun 25 23:05:24.906] Server {0xb0016000} DIAG: (cachekey) experimental/cachekey/pattern.cc:308:replace()
replacing '$1' with 'geo=country,state,city'
[Jun 25 23:05:24.906] Server {0xb0016000} DIAG: (cachekey) experimental/cachekey/pattern.cc:318:replace()
replacing '?$1' resulted in '?geo=country,state,city'
[Jun 25 23:05:24.906] Server {0xb0016000} DIAG: (cachekey) experimental/cachekey/cachekey.cc:348:appendPath()
added URI capture (path), key: 'http://example-cdn.com/path/file?geo=country%2Cstate%2Ccity'
[Jun 25 23:05:24.906] Server {0xb0016000} DIAG: (cachekey) experimental/cachekey/cachekey.cc:595:finalize()
finalizing cache key 'http://example-cdn.com/path/file?geo=country%2Cstate%2Ccity’


HTH! Please let me know how it goes!
Cheers,
—Gancho




> On Jun 25, 2018, at 10:02 AM, Chillin Gong <gongchunlin@gmail.com> wrote:
> 
> Hi, 
> 
> I am a new user of traffic server. Recently I am trying to migrate a product from ATS5
to latest ATS7. In ATS5, we use the cache feature, and use the cacheurl plugin and regular
expressions to extract partial value of a query parameter to comprise the cache key. However,
I didn't find corresponding feature in ATS7 cachekey plugin to get partial value of a query
parameter. 
> 
> For example, our request url is something like "/my/path?kw=test&geo=<country>,<state>,<city>,<street>".
In ATS5, we can get "geo=<country>,<state>,<city>" (without <street>)
as our cache key. However, I didn't find similar syntax to get such partial value with cachekey
plugin in ATS7. 
> https://docs.trafficserver.apache.org/en/7.0.x/admin-guide/plugins/cachekey.en.html <https://docs.trafficserver.apache.org/en/7.0.x/admin-guide/plugins/cachekey.en.html>
> 
> Does anyone know how I can achieve similar feature with cachekey plugin or other plugins?
> 
> 
> Thanks,
> Chunlin Gong
> 
> 


Mime
View raw message