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

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

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

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