Skip to content

Commit 2bcc996

Browse files
committed
updated docs to reflect recent changes.
1 parent 4b5b995 commit 2bcc996

File tree

3 files changed

+238
-42
lines changed

3 files changed

+238
-42
lines changed

README

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Status
99
This module is production ready.
1010

1111
Version
12-
This document describes srcache-nginx-module v0.22
13-
(<https://github.com/agentzh/srcache-nginx-module/tags>) released on 6
14-
August 2013.
12+
This document describes srcache-nginx-module v0.23
13+
(<https://github.com/agentzh/srcache-nginx-module/tags>) released on 27
14+
October 2013.
1515

1616
Synopsis
1717
upstream my_memcached {
@@ -276,6 +276,63 @@ Description
276276
(<http://openresty.org/>) 1.0.15.3 bundle or later, then you already
277277
have everything that you need here in the bundle.
278278

279+
Cache Key Preprocessing
280+
It is often desired to preprocess the cache key to exclude random noises
281+
that may hurt the cache hit rate. For example, random session IDs in the
282+
URI arguments are usually desired to get removed.
283+
284+
Consider the following URI querystring
285+
286+
SID=BC3781C3-2E02-4A11-89CF-34E5CFE8B0EF&UID=44332&L=EN&M=1&H=1&UNC=0&SRC=LK&RT=62
287+
288+
we want to remove the "SID" and "UID" arguments from it. It is easy to
289+
achieve if you use [[HttpLuaModule]] at the same time:
290+
291+
location = /t {
292+
rewrite_by_lua '
293+
local args = ngx.req.get_uri_args()
294+
args.SID = nil
295+
args.UID = nil
296+
ngx.req.set_uri_args(args)
297+
';
298+
299+
echo $args;
300+
}
301+
302+
Here we use the echo directive from [[HttpEchoModule]] to dump out the
303+
final value of $args in the end. You can replace it with your
304+
[[HttpSRCacheModule]] configurations and upstream configurations instead
305+
for your case. Let's test this /t interface with curl:
306+
307+
$ curl 'localhost:8081/t?RT=62&SID=BC3781C3-2E02-4A11-89CF-34E5CFE8B0EF&UID=44332&L=EN&M=1&H=1&UNC=0&SRC=LK'
308+
M=1&UNC=0&RT=62&H=1&L=EN&SRC=LK
309+
310+
It is worth mentioning that, if you want to retain the order of the URI
311+
arguments, then you can do string substitutions on the value of $args
312+
directly, for example,
313+
314+
location = /t {
315+
rewrite_by_lua '
316+
local args = ngx.var.args
317+
newargs, n, err = ngx.re.gsub(args, [[\b[SU]ID=[^&]*&?]], "", "jo")
318+
if n and n > 0 then
319+
ngx.var.args = newargs
320+
end
321+
';
322+
323+
echo $args;
324+
}
325+
326+
Now test it with the original curl command again, we get exactly what we
327+
would expect:
328+
329+
RT=62&L=EN&M=1&H=1&UNC=0&SRC=LK
330+
331+
But for caching purposes, it's good to normalize the URI argument order
332+
so that you can increase the cache hit rate. And the hash table entry
333+
order used by LuaJIT or Lua can be used to normalize the order as a nice
334+
side effect.
335+
279336
Directives
280337
srcache_fetch
281338
syntax: *srcache_fetch <method> <uri> <args>?*
@@ -922,22 +979,23 @@ Installation
922979
Alternatively, you can build Nginx with this module all by yourself:
923980

924981
* Grab the nginx source code from nginx.org (<http://nginx.org>), for
925-
example, the version 1.4.1 (see Nginx Compatibility),
982+
example, the version 1.4.3 (see Nginx Compatibility),
926983

927984
* and then apply the patch to your nginx source tree that fixes an
928985
important bug in the mainline Nginx core:
929986
https://raw.github.com/agentzh/ngx_openresty/master/patches/nginx-1.
930-
4.1-upstream_truncation.patch
987+
4.2-upstream_truncation.patch (you do NOT need this patch if you are
988+
using nginx 1.5.3 and later versions.)
931989

932990
* after that, download the latest version of the release tarball of
933991
this module from srcache-nginx-module file list
934992
(<http://github.com/agentzh/srcache-nginx-module/tags>),
935993

936994
* and finally build the Nginx source with this module
937995

938-
wget 'http://nginx.org/download/nginx-1.4.1.tar.gz'
939-
tar -xzvf nginx-1.4.1.tar.gz
940-
cd nginx-1.4.1/
996+
wget 'http://nginx.org/download/nginx-1.4.3.tar.gz'
997+
tar -xzvf nginx-1.4.3.tar.gz
998+
cd nginx-1.4.3/
941999

9421000
# Here we assume you would install you nginx under /opt/nginx/.
9431001
./configure --prefix=/opt/nginx \
@@ -949,7 +1007,7 @@ Installation
9491007
Compatibility
9501008
The following versions of Nginx should work with this module:
9511009

952-
* 1.4.x (last tested: 1.4.1)
1010+
* 1.4.x (last tested: 1.4.3)
9531011

9541012
* 1.3.x (last tested: 1.3.7)
9551013

0 commit comments

Comments
 (0)