]> git.ipfire.org Git - ipfire.org.git/commitdiff
iuse: Don't use memcache for caching
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Oct 2018 12:25:13 +0000 (13:25 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 Oct 2018 12:25:13 +0000 (13:25 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/web/handlers_iuse.py

index 70aa24b4a615ec8d4cf7094083b0b7d6d8ce7615..0c9643711f314e7c0e072a1ec3e26bee88d1009d 100644 (file)
@@ -16,6 +16,8 @@ class IUseImage(BaseHandler):
                        Select a random image from the errors directory
                        and return the content.
                """
+               self.set_expires(3600)
+
                self.set_header("Content-Type", "image/png")
 
                template_path = self.application.settings.get("template_path", "")
@@ -37,40 +39,21 @@ class IUseImage(BaseHandler):
 
                when = self.get_argument_date("when", None)
 
-               # Try to get the image from memcache. If we have a cache miss we
-               # build a new one.
-               mem_id = "iuse-%s-%s-%s" % (profile_id, image_id, self.locale.code)
-               if when:
-                       mem_id += "-%s" % when.isoformat()
-
-               cache = self.get_argument("cache", "true")
-               if cache == "true":
-                       image = self.memcached.get(mem_id)
-
-               if image:
-                       logging.debug("Got image from cache for profile: %s" % profile_id)
-               else:
-                       logging.info("Rendering new image for profile: %s" % profile_id)
+               logging.info("Rendering new image for profile: %s" % profile_id)
 
-                       profile = self.fireinfo.get_profile_with_data(profile_id, when=when)
-                       if not profile:
-                               raise tornado.web.HTTPError(404, "Profile '%s' was not found." % profile_id)
+               profile = self.fireinfo.get_profile_with_data(profile_id, when=when)
+               if not profile:
+                       raise tornado.web.HTTPError(404, "Profile '%s' was not found." % profile_id)
 
-                       image_cls = self.iuse.get_imagetype(image_id)
-                       if not image_cls:
-                               raise tornado.web.HTTPError(404, "Image class is unknown: %s" % image_id)
+               image_cls = self.iuse.get_imagetype(image_id)
+               if not image_cls:
+                       raise tornado.web.HTTPError(404, "Image class is unknown: %s" % image_id)
 
-                       # Render the image
-                       image = image_cls(self.backend, self, profile).to_string()
+               # Render the image
+               image = image_cls(self.backend, self, profile).to_string()
 
-                       # Save the image to the memcache
-                       self.memcached.set(mem_id, image, self.expires)
+               # Cache generate images for 3 hours
+               self.set_expires(3600 * 3)
 
                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)