From: Kirk Haines Date: 2005-08-07T02:08:44+09:00 Subject: Re: Remote require On Saturday 06 August 2005 7:28 am, James Britt wrote: > > Even so, it's easy enough to hack asimple version together, but the key > > would be caching (and checking for updates periodically?) > > I figure whenever the code is run it would just fetches the remote file > and get the latest version. Different story for long-running apps and > processes. Caching isn't a hard problem to solve. I have a Webcache class in my current IOWA source that should do the trick. It is based off of an LRU cache. It's not packaged seperately, but you're welcome to take it and modify as necessary, or you can tell me what you would like to see changed and I can seperate it into it's own mini-project. Current usage looks like this: cache_size = 20 webcache = Iowa::Webcache.new(cache_size) # defaults to 100 url = 'http://www.superbad.com/rubylib/soul.rb' content = webcache[url] It makes use of 'etag', 'last-modified', and 'expires' headers on content in order to try to do the correct thing regarding caching, and when asked for something it has already retrieved, just does a HEAD request on that item in order to try to determine if the content has changed. It was written for a specific purpose (a smart tag that automagically determines height and width of the image and puts that into the generated HTML), so it has a default or two that probably should become configurable items, such as the default time-to-live on content that doesn't have an 'expires' header. Thanks, Kirk Haines