-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.txt
125 lines (85 loc) · 3.96 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
repoze.accelerator
==================
An caching accelerator for WSGI applications. Intercepts responses
from downstream WSGI applications and caches responses based on
Cache-Control (and other) response header values. Serves up cached
responses to clients thereafter based on the policy specified by the
headers.
Configuration via Python
------------------------
Configure the middleware via Python::
import logging
from repoze.accelerator.policy import AcceleratorPolicy
from repoze.accelerator.storage import MemoryStorage
from repoze.accelerator.middleware import AcceleratorMiddleware
logger = logger.getLogger('repoze.accelerator')
storage = MemoryStorage(logger)
policy = AcceleratorPolicy(logger, storage)
middleware = AcceleratorMiddleware(app, policy, logger)
Configuration via Paste Deploy
------------------------------
Configure the paste.ini file like so::
[pipeline:main]
pipeline = egg:Paste#cgitb
egg:repoze.accelerator#accelerator
myapp
The Default Policy
------------------
The default policy is the AcceleratorPolicy. This policy has the
following features:
- Allow configuration of "vary" policies for both request headers
and request environment values.
- Allow specification of "allowed methods"; requests which don't use
one of these methods won't be served from cache.
- Allow specification of "honor_shift_reload": if Pragma: no-cache or
Cache-Control: no-cache exists in the request, and this value is true,
the response will not be served from cache even if it otherwise might
have been.
- Allow specification of "store_https_responses". If this is true,
we will store https responses and some information provided by
requests emitted via HTTPS.
When deciding whether we can fetch from our storage or not:
- If we honor shift-reload, and the request has a Pragma: no-cache
or Cache-Control: no-cache associated with it, don't try to
retrieve it from storage.
- If the request method doesn't match one of our allowed_methods,
don't try to retrieve it from storage.
- If the request has a Range, header, don't try to retrieve it
from storage.
- If the request is conditional (e.g. If-Modified-Since,
If-None-Match), don't try to retrieve it from storage.
- Otherwise, attempt to retrieve it from storage.
When deciding whether a value returned from storage should be
checked for freshness:
- If one representation stored matches the request headers and
environment, check it for freshness.
- Otherwise, abort.
To decide whether an item is fresh or not:
- If the entry in the cache is stale, don't serve from cache.
Staleness is defined as having a CC: max-age < (now -
entitydate) or an expires header whereby (expires - entitydate)
< (now - entitydate). Entities which don't have a Date header
are also considered stale.
When deciding whether we can store response data in our storage:
- If the request method doesn't match one of our allowed_methods,
don't store.
- If the response status is not 200 (OK) or 203 (Non-Authoritative
Information), don't store.
- If the response has a Cache-Control header or a Pragma header,
and either has 'no-cache' in its value, don't store.
- If the response has a Cache-Control header, and it has a max-age
of 0 or a max-age we don't understand, don't store.
- If the request is an https request, and "store_https_responses" is false,
don't store.
- If the response does not have a Date header, assume the date is now.
When storing data to storage:
- Store the status, the end-to-end headers in the response, and
information about request header and environment variance.
Mea Culpa
---------
There is not nearly enough documentation here to be considered
canonical. Apologies. Please read the source for more info for now.
Reporting Bugs / Development Versions
-------------------------------------
Visit http://github.com/repoze/repoze.accelerator/issues to report bugs.
Visit http://github.com/repoze to download development or tagged versions.