[Zope-Checkins] CVS: Zope/lib/python/App - ImageFile.py:1.16
Toby Dickenson
tdickenson@geminidataloggers.com
Mon, 15 Apr 2002 06:18:30 -0400
Update of /cvs-repository/Zope/lib/python/App
In directory cvs.zope.org:/tmp/cvs-serv28432/lib/python/App
Modified Files:
ImageFile.py
Log Message:
merged toby-cacheable-zmi-branch
=== Zope/lib/python/App/ImageFile.py 1.15 => 1.16 ===
from os import stat
import Acquisition
+import Globals
import os
-
class ImageFile(Acquisition.Explicit):
"""Image objects stored in external files."""
@@ -33,6 +33,13 @@
_prefix=package_home(_prefix)
path = os.path.join(_prefix, path)
self.path=path
+ if Globals.DevelopmentMode:
+ # In development mode, shorter is handy
+ max_age = 60
+ else:
+ # In production mode, longer reduces latency
+ max_age = 600
+ self.cch = 'public,max-age=%d' % max_age
file=open(path, 'rb')
data=file.read()
@@ -52,6 +59,9 @@
# HTTP If-Modified-Since header handling. This is duplicated
# from OFS.Image.Image - it really should be consolidated
# somewhere...
+ RESPONSE.setHeader('Content-Type', self.content_type)
+ RESPONSE.setHeader('Last-Modified', self.lmh)
+ RESPONSE.setHeader('Cache-Control', self.cch)
header=REQUEST.get_header('If-Modified-Since', None)
if header is not None:
header=header.split(';')[0]
@@ -72,8 +82,6 @@
RESPONSE.setStatus(304)
return ''
- RESPONSE.setHeader('Content-Type', self.content_type)
- RESPONSE.setHeader('Last-Modified', self.lmh)
f=open(self.path,'rb')
data=f.read()
f.close()