You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README
+86-19Lines changed: 86 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -9,9 +9,9 @@ Status
9
9
This module is production ready.
10
10
11
11
Version
12
-
This document describes srcache-nginx-module v0.13rc2
13
-
(<https://github.com/agentzh/srcache-nginx-module/tags>) released on 15
14
-
October 2011.
12
+
This document describes srcache-nginx-module v0.13rc6
13
+
(<https://github.com/agentzh/srcache-nginx-module/tags>) released on 16
14
+
March 2012.
15
15
16
16
Synopsis
17
17
upstream my_memcached {
@@ -64,6 +64,28 @@ Synopsis
64
64
# or even static files on the disk
65
65
}
66
66
67
+
map $request_method $skip_fetch {
68
+
default 0;
69
+
POST 1;
70
+
PUT 1;
71
+
}
72
+
73
+
server {
74
+
listen 8080;
75
+
76
+
location /api/ {
77
+
set $key "$uri?$args";
78
+
79
+
srcache_fetch GET /memc $key;
80
+
srcache_store PUT /memc $key;
81
+
82
+
srcache_methods GET PUT POST;
83
+
srcache_fetch_skip $skip_fetch;
84
+
85
+
# proxy_pass/drizzle_pass/content_by_lua/echo/...
86
+
}
87
+
}
88
+
67
89
Description
68
90
This module provides a transparent caching layer for arbitrary nginx
69
91
locations (like those use an upstream or even serve static disk files).
@@ -81,7 +103,7 @@ Description
81
103
security reasons.
82
104
83
105
Subrequest caching
84
-
For subrequests, we explicitly disallow the use of this module because
106
+
For *subrequests*, we explicitly disallow the use of this module because
85
107
it's too difficult to get right. There used to be an implementation but
86
108
it was buggy and I finally gave up fixing it and abandoned it.
87
109
@@ -205,7 +227,7 @@ Directives
205
227
206
228
context: *http, server, location, location if*
207
229
208
-
phase: *postaccess*
230
+
phase: *post-access*
209
231
210
232
This directive registers an access phase handler that will issue an
211
233
Nginx subrequest to lookup the cache.
@@ -230,7 +252,7 @@ Directives
230
252
231
253
context: *http, server, location, location if*
232
254
233
-
phase: *postaccess*
255
+
phase: *post-access*
234
256
235
257
The "<flag>" argument supports nginx variables. When this argument's
236
258
value is not empty *and* not equal to 0, then the fetching process will
@@ -258,14 +280,25 @@ Directives
258
280
}
259
281
where [[HttpLuaModule]] is used to calculate the value of the C<$skip> variable at the (earlier) rewrite phase. Similarly, the C<$key> variable can be computed by Lua using the L<set_by_lua|HttpLuaModule/"set_by_lua"> or L<rewrite_by_lua|HttpLuaModule/"rewrite_by_lua"> directive too.
260
282
283
+
The standard map directive can also be used to compute the value of the
284
+
$skip variable used in the sample above:
285
+
286
+
map $cookie_foo $skip {
287
+
default 0;
288
+
bar 1;
289
+
}
290
+
291
+
but your map statement should be put into the "http" config block in
292
+
your "nginx.conf" file though.
293
+
261
294
srcache_store
262
295
syntax: *srcache_store <method> <uri> <args>?*
263
296
264
297
default: *no*
265
298
266
299
context: *http, server, location, location if*
267
300
268
-
phase: *outputfilter*
301
+
phase: *output-filter*
269
302
270
303
This directive registers an output filter handler that will issue an
271
304
Nginx subrequest to save the response of the current main request into a
@@ -309,6 +342,8 @@ Directives
309
342
310
343
context: *http, server, location, location if*
311
344
345
+
phase: *output-header-filter*
346
+
312
347
When the response body length is exceeding this size, this module will
313
348
not try to store the response body into the cache using the subrequest
314
349
template that is specified in srcache_store.
@@ -326,7 +361,7 @@ Directives
326
361
327
362
context: *http, server, location, location if*
328
363
329
-
phase: *outputfilter*
364
+
phase: *output-header-filter*
330
365
331
366
The "<flag>" argument supports Nginx variables. When this argument's
332
367
value is not empty *and* not equal to 0, then the storing process will
@@ -350,7 +385,7 @@ Directives
350
385
351
386
context: *http, server, location, location if*
352
387
353
-
phase: *outputfilter*
388
+
phase: *output-header-filter*
354
389
355
390
This directive controls what responses to store to the cache according
356
391
to their status code.
@@ -375,7 +410,7 @@ Directives
375
410
376
411
context: *http, server, location, location if*
377
412
378
-
phase: *outputfilter*
413
+
phase: *output-header-filter*
379
414
380
415
This directive controles the header buffer when serializing response
381
416
headers for srcache_store. The default size is the page size, usually
@@ -394,7 +429,7 @@ Directives
394
429
395
430
context: *http, server, location, location if*
396
431
397
-
phase: *outputfilter*
432
+
phase: *output-header-filter*
398
433
399
434
By default, this module caches all the response headers except the
400
435
following ones:
@@ -436,7 +471,7 @@ Directives
436
471
437
472
context: *http, server, location, location if*
438
473
439
-
phase: *outputfilter*
474
+
phase: *output-header-filter*
440
475
441
476
By default, this module caches all the response headers except the
442
477
following ones:
@@ -479,7 +514,7 @@ Directives
479
514
480
515
context: *http, server, location*
481
516
482
-
phase: *output filter*
517
+
phase: *post-access, output-header-filter*
483
518
484
519
This directive specifies HTTP request methods that are considered by
485
520
either srcache_fetch or srcache_store. HTTP request methods not listed
@@ -498,7 +533,7 @@ Directives
498
533
499
534
context: *http, server, location, location if*
500
535
501
-
phase: *outputfilter*
536
+
phase: *output-header-filter*
502
537
503
538
When this directive is turned "off" (which is the default), non-empty
504
539
"Content-Encoding" response header will cause srcache_store skip storing
@@ -526,6 +561,8 @@ Directives
526
561
527
562
context: *http, server, location*
528
563
564
+
phase: *post-access, output-header-filter*
565
+
529
566
When this directive is turned "on", the request headers "Cache-Control"
530
567
and "Pragma" will be honored by this module in the following ways:
531
568
@@ -550,6 +587,8 @@ Directives
550
587
551
588
context: *http, server, location*
552
589
590
+
phase: *output-header-filter*
591
+
553
592
When this directive is turned "on", the response headers "Cache-Control"
554
593
and "Expires" will be honored by this module in the following ways:
555
594
@@ -577,7 +616,7 @@ Directives
577
616
578
617
context: *http, server, location*
579
618
580
-
phase: *outputfilter*
619
+
phase: *output-header-filter*
581
620
582
621
Turning this directive on will force responses with the header
583
622
"Cache-Control: no-store" to be stored into the cache when
@@ -593,7 +632,7 @@ Directives
593
632
594
633
context: *http, server, location*
595
634
596
-
phase: *outputfilter*
635
+
phase: *output-header-filter*
597
636
598
637
Turning this directive on will force responses with the header
599
638
"Cache-Control: no-cache" to be stored into the cache when
@@ -609,7 +648,7 @@ Directives
609
648
610
649
context: *http, server, location*
611
650
612
-
phase: *outputfilter*
651
+
phase: *output-header-filter*
613
652
614
653
Turning this directive on will force responses with the header
615
654
"Cache-Control: private" to be stored into the cache when
@@ -625,7 +664,7 @@ Directives
625
664
626
665
context: *http, server, location, location if*
627
666
628
-
phase: *outputfilter*
667
+
phase: *output-header-filter*
629
668
630
669
This directive controls the default expiration time period that is
631
670
allowed for the $srcache_expire variable value when neither
@@ -650,7 +689,7 @@ Directives
650
689
651
690
context: *http, server, location, location if*
652
691
653
-
phase: *outputfilter*
692
+
phase: *output-header-filter*
654
693
655
694
This directive controls the maximal expiration time period that is
656
695
allowed for the $srcache_expire variable value. This setting takes
@@ -714,6 +753,34 @@ Caveats
714
753
715
754
proxy_set_header Accept-Encoding "";
716
755
756
+
* Do *not* use [[HttpRewriteModule]]'s if directive in the same
757
+
location as this module's, because "if is evil". Instead, use
758
+
[[HttpMapModule]] or [[HttpLuaModule]] combined with this module's
759
+
srcache_store_skip and/or srcache_fetch_skip directives. For
760
+
example:
761
+
762
+
map $request_method $skip_fetch {
763
+
default 0;
764
+
POST 1;
765
+
PUT 1;
766
+
}
767
+
768
+
server {
769
+
listen 8080;
770
+
771
+
location /api/ {
772
+
set $key "$uri?$args";
773
+
774
+
srcache_fetch GET /memc $key;
775
+
srcache_store PUT /memc $key;
776
+
777
+
srcache_methods GET PUT POST;
778
+
srcache_fetch_skip $skip_fetch;
779
+
780
+
# proxy_pass/drizzle_pass/content_by_lua/echo/...
781
+
}
782
+
}
783
+
717
784
Installation
718
785
It's recommended to install this module as well as the Nginx core and
0 commit comments