Commit 7159fa5c authored by Toby Dickenson's avatar Toby Dickenson

merged toby-cacheable-zmi-branch

parent 6b6c466a
......@@ -12,7 +12,7 @@
##############################################################################
"""Image object that is stored in a file"""
__version__='$Revision: 1.15 $'[11:-2]
__version__='$Revision: 1.16 $'[11:-2]
from OFS.content_types import guess_content_type
from Globals import package_home
......@@ -21,9 +21,9 @@ from DateTime import DateTime
from time import time
from os import stat
import Acquisition
import Globals
import os
class ImageFile(Acquisition.Explicit):
"""Image objects stored in external files."""
......@@ -33,6 +33,13 @@ class ImageFile(Acquisition.Explicit):
_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 @@ class ImageFile(Acquisition.Explicit):
# 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 @@ class ImageFile(Acquisition.Explicit):
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()
......
<dtml-unless zmi_embedded_css>
<dtml-call "RESPONSE.setHeader('Content-Type','text/css')">
<dtml-call "RESPONSE.setHeader('Cache-Control','public,max-age=3600')">
</dtml-unless>
h1 {
font-family: Verdana, Helvetica, sans-serif;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment