Express.js Node Framework - Not caching

My Node.js app uses Express and my app has a route that sends a JSON file with Tweet data. I want it to cache for 20 seconds. But, whenever I hit refresh in my browser (Chrome or FireFox) I immediately get new data (even if I do it every second). Note that the data does change more than every 20 seconds, but I still want a 20 second cache.

Here is my route.

app.get('/tweet-stats.json', function(req, res) { res.set('Cache-Control', 'public, max-age=20'); res.set('Expires', new Date(Date.now() + 20000)); res.set('Last-Modified', new Date(Date.now())); res.set('Content-Type', 'application/json'); res.send(publicTweetStatus()); });

Here are the request and response headers from FireFox (FireBug):

Response Headers HTTP/1.1 200 OK X-Powered-By: Express Cache-Control: public, max-age=20 Expires: Fri May 10 2013 06:52:11 GMT+0000 (UTC) Last-Modified: Fri May 10 2013 06:51:51 GMT+0000 (UTC) Content-Type: application/json Content-Length: 209 Connection: keep-alive Request Headers GET /tweet-stats.json HTTP/1.1 Host: mydevelopmenturl.com User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive

How can I make browsers cache this for 20 seconds before checking with the server again?

UPDATE

So, I tried robertklep's suggestion and it worked in some browsers/OSs and not others:

Ubuntu Chrome - No Cache!!!!!!!!!!!!
Ubuntu FireFox - No Cache!!!!!!!!!!!!!!!
Windows 7 - Chrome - Cache
Windows 7 - FireFox - Cache
Windows 7 - IE 9 - Cache
Windows 7 - Opera - No Cache!!!!!!!!!!!!!!!!!
iOS Safari - Cache
Mac OSX - Safari - Cache
Mac OSX - Chrome - Cache
Mac OSX - Firefox - Cache

Why the differences?

Category:node.js Views:0 Time:2013-05-10

Related post

  • iPhone MapKit Framework to cache Google map for offline use 2010-09-25

    I am planning on a map project for hiking on iPhone. Since the area for hiking may not be covered by mobile network. Therefore, it is necessary to pre-cache the map (Google) of the area. 1) Can MapKit Framework support caching Google Map on iPhone lo

  • Express.js, Node.js Jade - Following the expressjs.com tutorials, and getting errors 2011-05-01

    Well I'm trying to get into Node.js / Express.js - however I've been having a few issue going through the screencast, the first issue, now resolved, was pretty obvious when it was spotted (Express.js, Node.js Jade vim). However, I'm now getting the f

  • Visual C# Express and Oracle database Express using entity framework 2011-08-09

    I'm trying to access my Oracle XE database using Visual C# Express and entity framework. I've tried installing oracleef (http://oracleef.codeplex.com/) but I'm not getting Oracle EF provider inside Visual C# Express add EF connection wizard, although

  • Is there anyway Express in Node.js can have more than one static folder? 2011-08-09

    I'm working on a project where there is a user uploaded collection of styles, scripts and images and then their is my app's collection of styles, scripts and images. They're two different places on my server. Is there anyway I can setup Express in No

  • Learning Express for Node.js 2011-11-15

    Anyone have pointers to good resources for learning Express? I'm aware of the documentation and the nodetuts.com videos. Curious if there are any other good resources out there. --------------Solutions------------- If I would do it all over again wit

  • .Net 4 Framework Object Caching and Tags 2012-01-17

    I had a look at .Net Framework Object Caching (System.Runtime.Caching) API and I do not see any support for attaching "tags" to cached objects. I was looking for an API similar to that of AppFabric which can support attaching tags to cached objects a

  • Express.js like framework for python 2011-07-04

    I'm looking for a very lightweight python framework. Similar to express.js for node. All I need is some basic routing functionality and some integration with an html templating language. Does anyone know of anything that would satisfy these requireme

  • How can I use a slug with Express and Node.js? 2011-12-20

    How can I go from: http://url:port/user?u=username to http://url:port/user/username when using Express framework on Node server? Current JavaScript server side code: app.get('/user', function(req, res){ var username = req.param("u"); users.findOne({u

  • Express.Js, Node.Js, MongoDB Questions 2012-02-18

    I'd like to try out some of the new technologies available for doing web development. I've been using php frameworks, rails and asp.net mvc for quite some time now and I saw that Node.Js provided a lot of good stuff to the table. But I don't know how

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.197 (s). 11 q(s)