I believe somthing like that was done years ago, but haven't heard
about it since. Think it was on the RAA.... Ah, here it is. I even
remembered the name correctly!
require 'soul' # Fetch from server if not found locally
Has anyone already implemented something like (I expect why_ to speak up
here)?
I should probably use hack 'require' to use open-uri, and play around,
but it's late and just wanted to toss this out.
What are the less-obvious issues with this way of fetching code? Let's
assume crypto code signing and authentication and the like.
James
Did something like this long ago in TaskMaster (Warning: I haven't
touched that code in years and as far as I know it doesn't work in 1.8.x).
Wasn't a webserver, but a drb server. Sent the code over via drb as I
recall.
One issue to consider (which I did not solve) is the issue of extensions
- you should probably send the C code over (or C++ if that's what you're
using) and compile it on the machine doing the require in case it has a
different processor/OS (as opposed to sending the .so file). It would be
cool if remote require worked with extensions as well.
We could really use something like this packaged up seperately in a
library/module - [I would recommend not using the code from TaskMaster as
an example it was written early on in my Ruby career and that was also
prior to the existence of open-uri.]
I believe somthing like that was done years ago, but haven't heard
about it since. Think it was on the RAA.... Ah, here it is. I even
remembered the name correctly!
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:
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 <img> 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
···
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.