Discussion:
How can I set partial value of a query parameter into cache key?
Chillin Gong
2018-06-25 17:02:17 UTC
Permalink
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

Does anyone know how I can achieve similar feature with cachekey plugin or
other plugins?


Thanks,
Chunlin Gong
Jeremy Payne
2018-06-25 22:56:36 UTC
Permalink
If you're open, you'll find what you're looking for in the lua plugin.
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
Does anyone know how I can achieve similar feature with cachekey plugin or
other plugins?
Thanks,
Chunlin Gong
Chillin Gong
2018-06-25 23:02:34 UTC
Permalink
Hi Jeremy,

Thanks for the reply! Do you mean there are some lua scripts that implement
the cache key feature, and they can be hooked into traffic server with lua
plugin? Do you have a sample lua script for it?


Regards,
Chunlin
Post by Jeremy Payne
If you're open, you'll find what you're looking for in the lua plugin.
Post by Chillin Gong
Hi,
I am a new user of traffic server. Recently I am trying to migrate a
product
Post by Chillin Gong
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
Post by Chillin Gong
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.
Post by Chillin Gong
For example, our request url is something like
"/my/path?kw=test&geo=<country>,<state>,<city>,<street>". In ATS5, we
can
Post by Chillin Gong
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
Post by Chillin Gong
Does anyone know how I can achieve similar feature with cachekey plugin
or
Post by Chillin Gong
other plugins?
Thanks,
Chunlin Gong
Jeremy Payne
2018-06-25 23:13:25 UTC
Permalink
i dont know if there is a cache url lua script already written.. but
if not, just follow examples in the below to write your own.

https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/plugins/ts_lua.en.html
Post by Chillin Gong
Hi Jeremy,
Thanks for the reply! Do you mean there are some lua scripts that implement
the cache key feature, and they can be hooked into traffic server with lua
plugin? Do you have a sample lua script for it?
Regards,
Chunlin
Post by Jeremy Payne
If you're open, you'll find what you're looking for in the lua plugin.
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
Does anyone know how I can achieve similar feature with cachekey plugin or
other plugins?
Thanks,
Chunlin Gong
Chillin Gong
2018-06-25 23:24:22 UTC
Permalink
I see. Thanks Jeremy! Will have a try to evaluate it later.

Besides this option, does anyone has any other options?


Regards,
Chunlin Gong
Post by Jeremy Payne
i dont know if there is a cache url lua script already written.. but
if not, just follow examples in the below to write your own.
https://docs.trafficserver.apache.org/en/7.1.x/admin-
guide/plugins/ts_lua.en.html
Post by Chillin Gong
Hi Jeremy,
Thanks for the reply! Do you mean there are some lua scripts that
implement
Post by Chillin Gong
the cache key feature, and they can be hooked into traffic server with
lua
Post by Chillin Gong
plugin? Do you have a sample lua script for it?
Regards,
Chunlin
Post by Jeremy Payne
If you're open, you'll find what you're looking for in the lua plugin.
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
Post by Chillin Gong
Post by Jeremy Payne
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.
Post by Chillin Gong
Post by Jeremy Payne
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
Post by Chillin Gong
Post by Jeremy Payne
Does anyone know how I can achieve similar feature with cachekey
plugin
Post by Chillin Gong
Post by Jeremy Payne
or
other plugins?
Thanks,
Chunlin Gong
Brian Geffon
2018-06-25 23:35:10 UTC
Permalink
If you don't mind coding you can write a C plugin that uses: TSCacheUrlSet:
https://docs.trafficserver.apache.org/en/latest/developer-guide/cache-architecture/api-functions.en.html.
Or you can also write a C++ plugin that uses Transaction.setCacheUrl():
https://github.com/apache/trafficserver/blob/master/lib/cppapi/include/atscppapi/Transaction.h#L272
Post by Chillin Gong
I see. Thanks Jeremy! Will have a try to evaluate it later.
Besides this option, does anyone has any other options?
Regards,
Chunlin Gong
Post by Jeremy Payne
i dont know if there is a cache url lua script already written.. but
if not, just follow examples in the below to write your own.
https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/plugins/ts_lua.en.html
Post by Chillin Gong
Hi Jeremy,
Thanks for the reply! Do you mean there are some lua scripts that
implement
Post by Chillin Gong
the cache key feature, and they can be hooked into traffic server with
lua
Post by Chillin Gong
plugin? Do you have a sample lua script for it?
Regards,
Chunlin
Post by Jeremy Payne
If you're open, you'll find what you're looking for in the lua plugin.
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
Post by Chillin Gong
Post by Jeremy Payne
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.
Post by Chillin Gong
Post by Jeremy Payne
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
Post by Chillin Gong
Post by Jeremy Payne
Does anyone know how I can achieve similar feature with cachekey
plugin
Post by Chillin Gong
Post by Jeremy Payne
or
other plugins?
Thanks,
Chunlin Gong
Zelkowitz, Evan
2018-06-26 00:57:20 UTC
Permalink
?Have you tried using the --include-params to set the params you want included in the key? Then you may have to add a --static-prefix= (empty space to wipe out the prefix) and --remote-path=true to also remove the path, hopefully just leaving you with the params you want as the key. You can enable the xdebug plugin and do curls with -H 'X-Debug: X-Cache-Key', to test and see how they turn out

________________________________
From: Brian Geffon <***@gmail.com>
Sent: Monday, June 25, 2018 5:35 PM
To: ***@trafficserver.apache.org
Subject: [EXTERNAL] Re: How can I set partial value of a query parameter into cache key?

If you don't mind coding you can write a C plugin that uses: TSCacheUrlSet: https://docs.trafficserver.apache.org/en/latest/developer-guide/cache-architecture/api-functions.en.html. Or you can also write a C++ plugin that uses Transaction.setCacheUrl(): https://github.com/apache/trafficserver/blob/master/lib/cppapi/include/atscppapi/Transaction.h#L272

On Mon, Jun 25, 2018 at 4:24 PM Chillin Gong <***@gmail.com<mailto:***@gmail.com>> wrote:
I see. Thanks Jeremy! Will have a try to evaluate it later.

Besides this option, does anyone has any other options?


Regards,
Chunlin Gong

On Mon, Jun 25, 2018 at 4:13 PM, Jeremy Payne <***@gmail.com<mailto:***@gmail.com>> wrote:
i dont know if there is a cache url lua script already written.. but
if not, just follow examples in the below to write your own.

https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/plugins/ts_lua.en.html
Post by Chillin Gong
Hi Jeremy,
Thanks for the reply! Do you mean there are some lua scripts that implement
the cache key feature, and they can be hooked into traffic server with lua
plugin? Do you have a sample lua script for it?
Regards,
Chunlin
Post by Jeremy Payne
If you're open, you'll find what you're looking for in the lua plugin.
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
Does anyone know how I can achieve similar feature with cachekey plugin or
other plugins?
Thanks,
Chunlin Gong
Zelkowitz, Evan
2018-06-26 01:00:41 UTC
Permalink
?Sorry, --remove-path=true

________________________________
From: Zelkowitz, Evan <***@comcast.com>
Sent: Monday, June 25, 2018 6:57 PM
To: ***@trafficserver.apache.org
Subject: [EXTERNAL] Re: How can I set partial value of a query parameter into cache key?


?Have you tried using the --include-params to set the params you want included in the key? Then you may have to add a --static-prefix= (empty space to wipe out the prefix) and --remote-path=true to also remove the path, hopefully just leaving you with the params you want as the key. You can enable the xdebug plugin and do curls with -H 'X-Debug: X-Cache-Key', to test and see how they turn out

________________________________
From: Brian Geffon <***@gmail.com>
Sent: Monday, June 25, 2018 5:35 PM
To: ***@trafficserver.apache.org
Subject: [EXTERNAL] Re: How can I set partial value of a query parameter into cache key?

If you don't mind coding you can write a C plugin that uses: TSCacheUrlSet: https://docs.trafficserver.apache.org/en/latest/developer-guide/cache-architecture/api-functions.en.html. Or you can also write a C++ plugin that uses Transaction.setCacheUrl(): https://github.com/apache/trafficserver/blob/master/lib/cppapi/include/atscppapi/Transaction.h#L272

On Mon, Jun 25, 2018 at 4:24 PM Chillin Gong <***@gmail.com<mailto:***@gmail.com>> wrote:
I see. Thanks Jeremy! Will have a try to evaluate it later.

Besides this option, does anyone has any other options?


Regards,
Chunlin Gong

On Mon, Jun 25, 2018 at 4:13 PM, Jeremy Payne <***@gmail.com<mailto:***@gmail.com>> wrote:
i dont know if there is a cache url lua script already written.. but
if not, just follow examples in the below to write your own.

https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/plugins/ts_lua.en.html
Post by Chillin Gong
Hi Jeremy,
Thanks for the reply! Do you mean there are some lua scripts that implement
the cache key feature, and they can be hooked into traffic server with lua
plugin? Do you have a sample lua script for it?
Regards,
Chunlin
Post by Jeremy Payne
If you're open, you'll find what you're looking for in the lua plugin.
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
Does anyone know how I can achieve similar feature with cachekey plugin or
other plugins?
Thanks,
Chunlin Gong
Chillin Gong
2018-06-26 01:58:53 UTC
Permalink
Brian, thanks for the guide! That's an option if there is no existing
plugin to support it.

Evan, I tried the options, but it includes the whole value string of the
parameter into the cache key. My case needs partial value into the key.
​Sorry, --remove-path=true
------------------------------
*Sent:* Monday, June 25, 2018 6:57 PM
*Subject:* [EXTERNAL] Re: How can I set partial value of a query
parameter into cache key?
​Have you tried using the --include-params to set the params you want
included in the key? Then you may have to add a --static-prefix= (empty
space to wipe out the prefix) and --remote-path=true to also remove the
path, hopefully just leaving you with the params you want as the key. You
can enable the xdebug plugin and do curls with -H 'X-Debug: X-Cache-Key',
to test and see how they turn out
------------------------------
*Sent:* Monday, June 25, 2018 5:35 PM
*Subject:* [EXTERNAL] Re: How can I set partial value of a query
parameter into cache key?
TSCacheUrlSet: https://docs.trafficserver.apache.org/en/latest/
developer-guide/cache-architecture/api-functions.en.html. Or you can also
https://github.com/apache/trafficserver/blob/master/lib/
cppapi/include/atscppapi/Transaction.h#L272
Post by Chillin Gong
I see. Thanks Jeremy! Will have a try to evaluate it later.
Besides this option, does anyone has any other options?
Regards,
Chunlin Gong
Post by Jeremy Payne
i dont know if there is a cache url lua script already written.. but
if not, just follow examples in the below to write your own.
https://docs.trafficserver.apache.org/en/7.1.x/admin-
guide/plugins/ts_lua.en.html
Post by Chillin Gong
Hi Jeremy,
Thanks for the reply! Do you mean there are some lua scripts that
implement
Post by Chillin Gong
the cache key feature, and they can be hooked into traffic server with
lua
Post by Chillin Gong
plugin? Do you have a sample lua script for it?
Regards,
Chunlin
Post by Jeremy Payne
If you're open, you'll find what you're looking for in the lua plugin.
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
Post by Chillin Gong
Post by Jeremy Payne
cacheurl plugin and regular expressions to extract partial value of
a
Post by Chillin Gong
Post by Jeremy Payne
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
Post by Chillin Gong
Post by Jeremy Payne
can
get "geo=<country>,<state>,<city>" (without <street>) as our cache
key.
Post by Chillin Gong
Post by Jeremy Payne
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
Post by Chillin Gong
Post by Jeremy Payne
Does anyone know how I can achieve similar feature with cachekey
plugin
Post by Chillin Gong
Post by Jeremy Payne
or
other plugins?
Thanks,
Chunlin Gong
Gancho Tenev
2018-06-26 06:27:24 UTC
Permalink
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
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
Chillin Gong
2018-06-28 18:22:52 UTC
Permalink
Hi Gancho,

Thanks for the great guide and debug tips! It worked well!


Regards,
Chunlin
Post by Gancho Tenev
Hello Chunlin,
There are examples of how to migrate from cacheurl.so to cachekey.so here
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) 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=
curl -v -x localhost:8080 'http://example-cdn.com/path/file?kw=test&
geo=country,state,city,street’
$ ./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
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
Does anyone know how I can achieve similar feature with cachekey plugin or other plugins?
Thanks,
Chunlin Gong
Continue reading on narkive:
Loading...