source: products/vendor/Products.CacheSetup/current/Products/CacheSetup/Extensions/policy_1.py @ 3296

Last change on this file since 3296 was 3296, checked in by fenix, 12 years ago

Load Products.CacheSetup?-1.2.1 into vendor/Products.CacheSetup?/current.

  • Property svn:eol-style set to native
File size: 16.1 KB
Line 
1from Products.CacheSetup import config
2
3# The old default policy -- default-cache-policy
4#
5# Renamed to with-caching-proxy to begin anew
6# with a "versionless" naming of policies
7# to make GenericSetup updates more sane
8
9POLICY_ID = "with-caching-proxy"
10POLICY_TITLE = "With Caching Proxy"
11
12def addCacheRules(rules):
13
14    id = 'httpcache'
15    if id not in rules.objectIds():
16        rules.invokeFactory(id=id, type_name='PolicyHTTPCacheManagerCacheRule')
17        rule = getattr(rules, id)
18        rule.setTitle('HTTPCache')
19        rule.setCacheManager('HTTPCache')
20        rule.setDescription('Rule for content associated with HTTPCache.  This content is cached in the proxy and in the browser.  ETags are not useful because these files have no personalization.')
21        rule.setCacheStop([])
22        rule.setLastModifiedExpression('python:object.modified()')
23        rule.setHeaderSetIdAnon('cache-in-browser-24-hours')
24        rule.setHeaderSetIdAuth('cache-in-browser-24-hours')
25        rule.setVaryExpression('python:getattr(object, \'meta_type\', None) not in [\'Filesystem Image\', \'Image\'] and rule.portal_cache_settings.getVaryHeader() or \'\'')
26       
27    id = 'plone-content-types'
28    if id not in rules.objectIds():
29        rules.invokeFactory(id=id, type_name='ContentCacheRule')
30        rule = getattr(rules, id)
31        rule.setTitle('Content')
32        rule.setDescription('Rule for views of plone content types.  Anonymous users are served content object views from memory, not the proxy cache (because the navigation tree displayed might change without triggering a proxy cache purge).  Responses for authenticated users are not cached in memory or proxy (because caching personalized pages is inefficient) but an ETag is added to enable proper 304 responses.  Member ID is used in the ETag because content is personalized; the time of the last catalog change is included so that the navigation tree stays up to date.')
33        rule.setContentTypes(['Document', 'Event', 'Link', 'News Item', 'Image', 'File'])
34        rule.setDefaultView(True)
35        rule.setTemplates([])
36        rule.setCacheStop(['portal_status_message','statusmessages','SearchableText'])
37        rule.setLastModifiedExpression('python:object.modified()')
38        rule.setHeaderSetIdAnon('cache-in-memory')
39        rule.setHeaderSetIdAuth('cache-with-etag')
40        rule.setEtagComponents(['member','catalog_modified','language','gzip','skin','object_locked'])
41        rule.setEtagRequestValues(['month','year','orig_query'])
42        rule.setEtagTimeout(3600)
43        rule.setPurgeExpression('python:object.getImageAndFilePurgeUrls()')
44       
45    id = 'plone-containers'
46    if id not in rules.objectIds():
47        rules.invokeFactory(id=id, type_name='ContentCacheRule')
48        rule = getattr(rules, id)
49        rule.setTitle('Containers')
50        rule.setDescription('Rule for views of Plone containers.  Anonymous users are served pages from memory, not the proxy cache (because we can\'t easily purge container views when they change since container views depend on all of their contained objects, and contained objects do not necessarily purge their containers\' views when they change).  Responses for authenticated users are not cached in memory or proxy (because caching personalized pages is inefficient) but an ETag is added to enable proper 304 responses.  Member ID is used in the ETag because content is personalized; the time of the last catalog change is included so that the contents and the navigation tree stays up to date.')
51        rule.setContentTypes(['Topic', 'Folder', 'Plone Site', 'Large Plone Folder'])
52        rule.setDefaultView(True)
53        rule.setTemplates(['folder_contents'])
54        rule.setCacheStop(['portal_status_message','statusmessages','SearchableText'])
55        rule.setLastModifiedExpression('python:object.modified()')
56        rule.setHeaderSetIdAnon('cache-in-memory')
57        rule.setHeaderSetIdAuth('cache-with-etag')
58        rule.setEtagComponents(['member','catalog_modified','language','gzip','skin','object_locked'])
59        rule.setEtagRequestValues(['b_start','month','year','orig_query'])
60        rule.setEtagExpression('python:request.get(\'__cp\',None) is not None')
61        rule.setEtagTimeout(3600)
62       
63    id = 'plone-templates'
64    if id not in rules.objectIds():
65        rules.invokeFactory(id=id, type_name='TemplateCacheRule')
66        rule = getattr(rules, id)
67        rule.setTitle('Templates')
68        rule.setDescription('Rule for various non-form templates.  Anonymous users are served pages from memory, not the proxy cache (because some of these templates depend on catalog queries).  Responses for authenticated users are not cached in memory or proxy (because caching personalized pages is inefficient) but an ETag is added to enable proper 304 responses.  Member ID is used in the ETag because content is personalized; the time of the last catalog change is included so that the contents and the navigation tree stays up to date.')
69        rule.setTemplates(['accessibility-info','sitemap','recently_modified'])
70        rule.setCacheStop(['portal_status_message','statusmessages','SearchableText'])
71        rule.setLastModifiedExpression('python:object.modified()')
72        rule.setHeaderSetIdAnon('cache-in-memory')
73        rule.setHeaderSetIdAuth('cache-with-etag')
74        rule.setEtagComponents(['member','catalog_modified','language','gzip','skin'])
75        rule.setEtagRequestValues(['b_start','month','year','orig_query'])
76        rule.setEtagTimeout(3600)
77   
78    id = 'plone-rss'
79    if id not in rules.objectIds():
80        rules.invokeFactory(id=id, type_name='TemplateCacheRule')
81        rule = getattr(rules, id)
82        rule.setTitle('RSS')
83        rule.setDescription('Rule for RSS feeds.  Anonymous queries are cached in proxy.')
84        rule.setTemplates(['RSS','search_rss'])
85        rule.setCacheStop([])
86        rule.setLastModifiedExpression('python:object.modified()')
87        rule.setHeaderSetIdAnon('cache-in-proxy-1-hour')
88        rule.setHeaderSetIdAuth('cache-with-etag')
89        rule.setEtagComponents(['member','catalog_modified','language','gzip','skin'])
90        rule.setEtagRequestValues(['SearchableText'])
91        rule.setEtagTimeout(None)
92
93    id = 'resource-registries'
94    if id not in rules.objectIds():
95        rules.invokeFactory(id=id, type_name='PolicyHTTPCacheManagerCacheRule')
96        rule = getattr(rules, id)
97        rule.setTitle('CSS, JS & KSS')
98        rule.setDescription('Rule for CSS, JS, and KSS generated by ResourceRegistries.  These files are cached "forever" (1 year) in proxy caches and in browsers.  There is no need to purge these files because when they are changed and saved in portal_css/portal_js, their file names change.  ETags are not useful because these files have no personalization.')
99        rule.setCacheManager(config.OFS_CACHE_ID)
100        rule.setCacheStop([])
101        rule.setLastModifiedExpression('python:object.modified()')
102        rule.setTypes(['File'])
103        rule.setHeaderSetIdAnon('expression')
104        rule.setHeaderSetIdAuth('expression')
105        rule.setHeaderSetIdExpression('python:object.getHeaderSetIdForResource()')
106        rule.setVaryExpression('string:')
107
108    id = 'downloads'
109    if id not in rules.objectIds():
110        rules.invokeFactory(id=id, type_name='PolicyHTTPCacheManagerCacheRule')
111        rule = getattr(rules, id)
112        rule.setTitle('Files & Images')
113        rule.setDescription('Rule for ATFile and ATImage downloads.  Files that are viewable by Anonymous users are cached in the proxy cache.  ETags are not useful because these files have no personalization.')
114        rule.setCacheManager(config.OFS_CACHE_ID)
115        rule.setTypes(['Image', 'File'])
116        rule.setCacheStop([])
117        rule.setLastModifiedExpression('python:object.modified()')
118        rule.setHeaderSetIdAnon('expression')
119        rule.setHeaderSetIdAuth('expression')
120        rule.setHeaderSetIdExpression('python:object.portal_cache_settings.canAnonymousView(object) and \'cache-in-proxy-24-hours\' or \'no-cache\'')
121        rule.setVaryExpression('string:')
122
123    id = 'dtml-css'
124    if id not in rules.objectIds():
125        rules.invokeFactory(id=id, type_name='TemplateCacheRule')
126        rule = getattr(rules, id)
127        rule.setTitle('DTML CSS files')
128        rule.setDescription('Rule for css files generated with DTML.  These files will be cached in the browser for 24 hours.')
129        rule.setTemplates(['IEFixes.css'])
130        rule.setCacheStop([])
131        rule.setLastModifiedExpression('python:object.modified()')
132        rule.setHeaderSetIdAnon('cache-in-browser-24-hours')
133        rule.setHeaderSetIdAuth('cache-in-browser-24-hours')
134        rule.setEtagComponents([])
135        rule.setEtagRequestValues([])
136        rule.setEtagTimeout(None)
137        rule.setVaryExpression('string:')
138
139    for rule in rules.objectValues():
140        rule.unmarkCreationFlag()
141        rule.reindexObject()
142
143def addHeaderSets(header_sets):
144
145    id = 'no-cache'
146    if not id in header_sets.objectIds():
147        header_sets.invokeFactory(id=id, type_name='HeaderSet')
148        hs = getattr(header_sets, id)
149        hs.setTitle('Do not cache')
150        hs.setDescription('Should not be cached in proxy.  Browser cache should revalidate every time.')
151        hs.setPageCache(0)
152        hs.setLastModified('yes')
153        hs.setEtag(0)
154        hs.setEnable304s(0)
155        hs.setVary(True)
156        hs.setMaxAge(0)
157        hs.setSMaxAge(0)
158        hs.setMustRevalidate(1)
159        hs.setProxyRevalidate(0)
160        hs.setNoCache(0)
161        hs.setNoStore(0)
162        hs.setPublic(0)
163        hs.setPrivate(1)
164        hs.setNoTransform(0)
165        hs.setPreCheck(None)
166        hs.setPostCheck(None)
167
168    id = 'cache-in-memory'
169    if not id in header_sets.objectIds():
170        header_sets.invokeFactory(id=id, type_name='HeaderSet')
171        hs = getattr(header_sets, id)
172        hs.setTitle('Cache in Memory')
173        hs.setDescription('Page should be cached in memory on the server.  Page should not be cached in a proxy cache but may be conditionally cached in the browser.  The browser should validate the page\'s ETag before displaying a cached page.')
174        hs.setPageCache(1)
175        hs.setLastModified('delete')
176        hs.setEtag(1)
177        hs.setEnable304s(1)
178        hs.setVary(True)
179        hs.setMaxAge(0)
180        hs.setSMaxAge(0)
181        hs.setMustRevalidate(1)
182        hs.setProxyRevalidate(0)
183        hs.setNoCache(0)
184        hs.setNoStore(0)
185        hs.setPublic(0)
186        hs.setPrivate(1)
187        hs.setNoTransform(0)
188        hs.setPreCheck(None)
189        hs.setPostCheck(None)
190
191    id = 'cache-with-etag'
192    if not id in header_sets.objectIds():
193        header_sets.invokeFactory(id=id, type_name='HeaderSet')
194        hs = getattr(header_sets, id)
195        hs.setTitle('Cache with ETag')
196        hs.setDescription('Page should not be cached in a proxy cache but may be conditionally cached in the browser.  The browser should validate the page\'s ETag before displaying a cached page.')
197        hs.setPageCache(0)
198        hs.setLastModified('delete')
199        hs.setEtag(1)
200        hs.setEnable304s(1)
201        hs.setVary(True)
202        hs.setMaxAge(0)
203        hs.setSMaxAge(0)
204        hs.setMustRevalidate(1)
205        hs.setProxyRevalidate(0)
206        hs.setNoCache(0)
207        hs.setNoStore(0)
208        hs.setPublic(0)
209        hs.setPrivate(1)
210        hs.setNoTransform(0)
211        hs.setPreCheck(None)
212        hs.setPostCheck(None)
213
214    id = 'cache-with-last-modified'
215    if not id in header_sets.objectIds():
216        header_sets.invokeFactory(id=id, type_name='HeaderSet')
217        hs = getattr(header_sets, id)
218        hs.setTitle('Cache file with Last-Modified')
219        hs.setDescription('File should not be cached in a proxy cache but may be conditionally cached in the browser.  The browser should validate the file\'s Last-Modified time before displaying a cached file.')
220        hs.setPageCache(0)
221        hs.setLastModified('yes')
222        hs.setEtag(0)
223        hs.setEnable304s(1)
224        hs.setVary(True)
225        hs.setMaxAge(0)
226        hs.setSMaxAge(0)
227        hs.setMustRevalidate(1)
228        hs.setProxyRevalidate(0)
229        hs.setNoCache(0)
230        hs.setNoStore(0)
231        hs.setPublic(0)
232        hs.setPrivate(1)
233        hs.setNoTransform(0)
234        hs.setPreCheck(None)
235        hs.setPostCheck(None)
236
237    id = 'cache-in-proxy-1-hour'
238    if not id in header_sets.objectIds():
239        header_sets.invokeFactory(id=id, type_name='HeaderSet')
240        hs = getattr(header_sets, id)
241        hs.setTitle('Cache in proxy cache for 1 hour')
242        hs.setDescription('Should be cached in both proxy and browser.  Proxy should revalidate after 1 hour.  Browser should revalidate immediately.')
243        hs.setPageCache(0)
244        hs.setLastModified('yes')
245        hs.setEtag(0)
246        hs.setEnable304s(0)
247        hs.setVary(True)
248        hs.setMaxAge(0)
249        hs.setSMaxAge(3600)
250        hs.setMustRevalidate(1)
251        hs.setProxyRevalidate(0)
252        hs.setNoCache(0)
253        hs.setNoStore(0)
254        hs.setPublic(0)
255        hs.setPrivate(0)
256        hs.setNoTransform(0)
257        hs.setPreCheck(None)
258        hs.setPostCheck(None)
259
260    id = 'cache-in-proxy-24-hours'
261    if not id in header_sets.objectIds():
262        header_sets.invokeFactory(id=id, type_name='HeaderSet')
263        hs = getattr(header_sets, id)
264        hs.setTitle('Cache in proxy cache for 24 hours')
265        hs.setDescription('Should be cached in both proxy and browser.  Proxy should revalidate after 24 hours.  Browser should revalidate immediately')
266        hs.setPageCache(0)
267        hs.setLastModified('yes')
268        hs.setEtag(0)
269        hs.setEnable304s(0)
270        hs.setVary(True)
271        hs.setMaxAge(0)
272        hs.setSMaxAge(24*3600)
273        hs.setMustRevalidate(1)
274        hs.setProxyRevalidate(1)
275        hs.setNoCache(0)
276        hs.setNoStore(0)
277        hs.setPublic(0)
278        hs.setPrivate(0)
279        hs.setNoTransform(0)
280        hs.setPreCheck(None)
281        hs.setPostCheck(None)
282
283    id = 'cache-in-browser-1-hour'
284    if not id in header_sets.objectIds():
285        header_sets.invokeFactory(id=id, type_name='HeaderSet')
286        hs = getattr(header_sets, id)
287        hs.setTitle('Cache in browser for 1 hour')
288        hs.setDescription('Should be cached in both proxy and browser.  Both should revalidate after 1 hour.')
289        hs.setPageCache(0)
290        hs.setLastModified('yes')
291        hs.setEtag(0)
292        hs.setEnable304s(0)
293        hs.setVary(True)
294        hs.setMaxAge(3600)
295        hs.setSMaxAge(3600)
296        hs.setMustRevalidate(1)
297        hs.setProxyRevalidate(1)
298        hs.setNoCache(0)
299        hs.setNoStore(0)
300        hs.setPublic(1)
301        hs.setPrivate(0)
302        hs.setNoTransform(0)
303        hs.setPreCheck(None)
304        hs.setPostCheck(None)
305
306    id = 'cache-in-browser-24-hours'
307    if not id in header_sets.objectIds():
308        header_sets.invokeFactory(id=id, type_name='HeaderSet')
309        hs = getattr(header_sets, id)
310        hs.setTitle('Cache in browser for 24 hours')
311        hs.setDescription('Should be cached in both proxy and browser.  Both should revalidate after 24 hours.')
312        hs.setPageCache(0)
313        hs.setLastModified('yes')
314        hs.setEtag(0)
315        hs.setEnable304s(0)
316        hs.setVary(True)
317        hs.setMaxAge(24*3600)
318        hs.setSMaxAge(24*3600)
319        hs.setMustRevalidate(1)
320        hs.setProxyRevalidate(1)
321        hs.setNoCache(0)
322        hs.setNoStore(0)
323        hs.setPublic(1)
324        hs.setPrivate(0)
325        hs.setNoTransform(0)
326        hs.setPreCheck(None)
327        hs.setPostCheck(None)
328
329    id = 'cache-in-browser-forever'
330    if not id in header_sets.objectIds():
331        header_sets.invokeFactory(id=id, type_name='HeaderSet')
332        hs = getattr(header_sets, id)
333        hs.setTitle('Cache in browser forever')
334        hs.setDescription('Should be cached in both proxy and browser.  Both should revalidate after 1 year.')
335        hs.setPageCache(0)
336        hs.setLastModified('yes')
337        hs.setEtag(0)
338        hs.setEnable304s(0)
339        hs.setVary(True)
340        hs.setMaxAge(365*24*3600)
341        hs.setSMaxAge(365*24*3600)
342        hs.setMustRevalidate(0)
343        hs.setProxyRevalidate(0)
344        hs.setNoCache(0)
345        hs.setNoStore(0)
346        hs.setPublic(1)
347        hs.setPrivate(0)
348        hs.setNoTransform(0)
349        hs.setPreCheck(None)
350        hs.setPostCheck(None)
351
352    for hs in header_sets.objectValues():
353        hs.unmarkCreationFlag()
354        hs.reindexObject()
355
Note: See TracBrowser for help on using the repository browser.