return res
def get_content(self, uuid):
- # Try fetching the object from memcache. If found, we return it right away.
- content = self.memcache.get("nopaste-%s" % uuid)
-
- # 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, 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 when it has been requested a couple
- # of times
- if res.views >= 5:
- self.memcache.set("nopaste-%s" % uuid, content, 6 * 3600)
+ res = self.db.get("SELECT content FROM nopaste \
+ WHERE uuid = %s", uuid)
- return content
+ if res:
+ return res.content
def _update_lastseen(self, uuid):
self.db.execute("UPDATE nopaste SET time_lastseen = NOW(), views = views + 1 \