[Zope-Checkins] CVS: Zope/lib/python/App - ImageFile.py:1.15.40.1
Toby Dickenson
tdickenson@geminidataloggers.com
Fri, 12 Apr 2002 10:55:17 -0400
Update of /cvs-repository/Zope/lib/python/App
In directory cvs.zope.org:/tmp/cvs-serv31146/lib/python/App
Modified Files:
Tag: toby-cacheable-zmi-branch
ImageFile.py
Log Message:
collector 196; better caching of ZMI
=== Zope/lib/python/App/ImageFile.py 1.15 => 1.15.40.1 ===
from os import stat
import Acquisition
+import Globals
import os
-
class ImageFile(Acquisition.Explicit):
"""Image objects stored in external files."""
- def __init__(self,path,_prefix=None):
+ def __init__(self,path,_prefix=None,max_age=None):
if _prefix is None: _prefix=SOFTWARE_HOME
elif type(_prefix) is not type(''):
_prefix=package_home(_prefix)
path = os.path.join(_prefix, path)
self.path=path
+ self.cch = 'public'
+ if max_age is None:
+ # Use a default value
+ if Globals.DevelopmentMode:
+ # In development mode, shorter is handy
+ max_age = 60
+ else:
+ # In production mode, longer saves bandwith and latency
+ max_age = 600
+ if max_age:
+ self.cch += ', max-age=%d' % max_age
file=open(path, 'rb')
data=file.read()
@@ -52,6 +63,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 +86,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()