[jala-dev] Re: caching remote content

  • From: <robert.gaggl@xxxxxx>
  • To: <jala-dev@xxxxxxxxxxxxx>
  • Date: Mon, 7 May 2007 16:01:03 +0200

hi anton,

using setInterval(Date.ONEMINUTE) defines that the cached remote content
object will "expire" one minute after it has been created. Note that
this does *not* mean that the remote content will be automatically
re-fetched if you create a new RemoteContent object with the same Url
after the expiry of the cached one. It basically just defines the time
when needsUpdate() of a RemoteContent instance returns true. So your
code needs to call update() whenever needsUpdate() returns true,
otherwise you'll be using the cached content forever. So a probably
better example for [1] would be:

Root.prototype.main_action = function() {
   var remote = new jala.RemoteContent("http://zombo.com";);
   if (remote.needsUpdate()) {
      remote.setHeader("X-RemoteContent-Host", req.data.http_host);
      remote.setInterval(Date.ONEMINUTE);
      remote.update();
   }
   res.write(remote.toString());
   return;
};

This way the remote content at the given url is fetched only once a
minute.

The second code example loops over all cached RemoteContent objects on
disk and removes those that expired, so the next time the remote content
will be re-retrieved and again cached locally on disk. This way you'll
only have those RemoteContent objects cached on disk that have actually
been used within the expiry interval.

robert


-----Original Message-----
From: jala-dev-bounce@xxxxxxxxxxxxx
[mailto:jala-dev-bounce@xxxxxxxxxxxxx] On Behalf Of Anton Pirker
Sent: Montag, 07. Mai 2007 15:27
To: jala-dev@xxxxxxxxxxxxx
Subject: [jala-dev] caching remote content

hi jala-folks!

I am just playing around with the RemoteContent object.
I have a question about the caching: When i use the sourcecode from the 
example [1] in the module documentation, the content is cached for a 
minute? Do i get that right?

What for is the second part [2] of the sample code?


Would be nice if some could bring in some light!

Thanks in advance,
Anton



[1] https://opensvn.csie.org/traccgi/jala/wiki/JalaModules#RemoteContent

Root.prototype.main_action = function() {
   var remote = new jala.RemoteContent("http://zombo.com";);
   remote.setHeader("X-RemoteContent-Host", req.data.http_host);
   remote.setInterval(Date.ONEMINUTE);
   remote.update();
   res.write(remote.toString());
   return;
};


[2]
https://opensvn.csie.org/traccgi/jala/wiki/JalaModules#RemoteContent:

global.scheduler = function() {
   jala.RemoteContent.exec(function(remoteContent) {
      if (remoteContent.needsUpdate()) {
         remoteContent.clear();
      }
      return;
   });
};




Other related posts: