Exemplo n.º 1
0
    def get(self):
        posts = BlogPost.get_all_posts()

        res = []
        for post in posts:
            post_json = post.to_json()
            res.append(post_json)

        self.response.headers.add_header("Content-Type", "application/json; charset=utf-8")
        self.write(json.dumps(res))
Exemplo n.º 2
0
    def get(self):
        posts = memcache.get(POSTS_KEY)
        t = memcache.get(POSTS_TIME_KEY)

        if not posts or not t:
            posts = BlogPost.get_all_posts()
            t = time.time()
            memcache.set(POSTS_KEY, posts)
            memcache.set(POSTS_TIME_KEY, t)

        t = int (time.time() - t)
            
        self.render('blog.html', posts = posts, posts_generated = t)