From d7c4018be248cdbfed6668c387ab4160a517b214 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 28 Apr 2015 11:06:18 +0200 Subject: [PATCH] i-use: Send expiry headers --- webapp/handlers_iuse.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/webapp/handlers_iuse.py b/webapp/handlers_iuse.py index b9355245..4fce56d8 100644 --- a/webapp/handlers_iuse.py +++ b/webapp/handlers_iuse.py @@ -1,5 +1,6 @@ #!/usr/bin/python +import datetime import logging import os import random @@ -9,6 +10,8 @@ from handlers_base import * import backend class IUseImage(BaseHandler): + expires = 3600 * 3 + def write_error(self, status_code, **kwargs): """ Select a random image from the errors directory @@ -61,8 +64,14 @@ class IUseImage(BaseHandler): # Render the image image = image_cls(self.backend, self, profile).to_string() - # Save the image to the memcache for 60 minutes - self.memcached.set(mem_id, image, 3600) + # Save the image to the memcache + self.memcached.set(mem_id, image, self.expires) self.set_header("Content-Type", "image/png") + + # Set expiry headers + self.set_header("Expires", + datetime.datetime.utcnow() + datetime.timedelta(seconds=self.expires)) + self.set_header("Cache-Control", "public,max-age=%d" % self.expires) + self.write(image) -- 2.47.2