how to use nitro/cache

88 views
Skip to first unread message

Roberto Saccon

unread,
Mar 30, 2010, 2:19:00 AM3/30/10
to nitro-devel
Is there anywhere an example or an explanation how the nitro page
caching is supposed to be used ?

--
Roberto

George Moschovitis

unread,
Mar 30, 2010, 3:15:30 AM3/30/10
to nitro...@googlegroups.com
here is an example:

var cacheLastModified = require("nitro/cache").cacheLastMofified;

exports.GET = function (env) {
    var params = new Request(env).GET(),
        a = Article.get(params.key);
        
    if (!a) return Response.notFound();

    return cacheLastModified(env, a.updated, function(env) {        
        return {data: {
            article: {
                key: a.key(),
                title: a.title,
                content: a.content,
                created: a.created,
                author: a.author.name(),
                commentCount: a.commentCount,
                comments: a.comments().order("created").fetch().map(function (c) {
                    return {
                        key: c.key(),
                        author: c.author.name(),
                        content: c.content,
                        created: c.created
                    }
                })
            }    
        }}
    });        
}

you can be more clever and store the updated in memcache (or even in a variable).

-g.


--
You received this message because you are subscribed to the Google Groups "nitro-devel" group.
To post to this group, send email to nitro...@googlegroups.com.
To unsubscribe from this group, send email to nitro-devel...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nitro-devel?hl=en.




--
http://www.gmosx.com/blog

Roberto Saccon

unread,
Mar 30, 2010, 5:37:45 AM3/30/10
to nitro-devel
thanks, that helped.

On Mar 30, 4:15 am, George Moschovitis <george-moschovi...@gmosx.com>
wrote:

> > nitro-devel...@googlegroups.com<nitro-devel%2Bunsubscribe@googlegr oups.com>

Reply all
Reply to author
Forward
0 new messages