From: Michael Tremer Date: Sun, 31 May 2015 11:42:19 +0000 (+0200) Subject: nopaste: Put content in memcache only for frequently requested stuff X-Git-Url: http://git.ipfire.org/?p=ipfire.org.git;a=commitdiff_plain;h=422411da38b8c156b83f43628658f21590283c16 nopaste: Put content in memcache only for frequently requested stuff --- diff --git a/webapp/backend/nopaste.py b/webapp/backend/nopaste.py index 7db578a3..af339374 100644 --- a/webapp/backend/nopaste.py +++ b/webapp/backend/nopaste.py @@ -68,13 +68,15 @@ class Nopaste(Object): # If the object was not in the cache, we need to fetch it from the database. if not content: - res = self.db.get("SELECT content FROM nopaste WHERE uuid = %s", uuid) + res = self.db.get("SELECT content, views FROM nopaste WHERE uuid = %s", uuid) # Convert the content to a byte string content = "%s" % res.content - # Save it in the cache for later - self.memcache.set("nopaste-%s" % uuid, content, 6 * 3600) + # Save it in the cache for later when it has been requested a couple + # of times + if res.views >= 5: + self.memcache.set("nopaste-%s" % uuid, content, 6 * 3600) return content