def fetch_cached(self, query, num=100, cached=True, page=1): page = force_int(page, 1) num = force_int(num, 100) offset = 0 if page > 1: offset = (page - 1) * num logging.info('sketch.mode.fetch_cached: %s' % query) dat_key = "models.%s" % base64.b64encode(query) dat = memcache.get(dat_key) if dat is not None and cached: logging.info('cache hit') if num == 1: return dat[0] return dat[offset:offset + num] try: query = db.GqlQuery(query) if query.count() == 0: # logging.info('return on') return [] resultset = query.fetch(num, offset) # logging.info(len(resultset)) if resultset and type(resultset) == type([]): r = memcache.set(dat_key, resultset, 60 * 60) if num == 1: return resultset[0] return resultset return [] except BadQueryError, e: logging.error('DB query error: %s in query: %s' % (str(e), query)) return []
def get(self, page=1): page = force_int(page, 1) posts = buckley.models.Post.get_posts_published(num=5, page=page) return self.render('archive', { 'posts': posts, 'page': page })