MJD was talking about Memoize. Here it is in Ruby:
module Memoize
def memoize(func_name)
cache = {}
(class<<elf; self; end).send(:define_method, func_name) { |*args|
return cache[args] if cache.has_key? args
cache[args] = super
}
end
endThere’s a lot of code in the Perl Memoize module; maybe it does other things—I haven’t really looked. Oh, and here’s this Memoize module from RAA. I’m some months late. :-)
Here’s some pictures from Portland.
2006-07-24 10:22 pm (UTC)
In your solutions for making cross-domain requests, you can also mention Flash as an option: all requests can be routed through an invisible Flash object on the page. If you have a crossdomain.xml on the server (which most services have), you're set.
2006-07-24 10:31 pm (UTC)
Ruby vs Perl
2006-07-25 03:10 am (UTC)
The only feature his module has over mine is the ability to "unmemoize".
- Dan
Re: Ruby vs Perl
2006-07-31 07:04 am (UTC)
In fact, a lot of the crappiness of the Memoize module is just bad design.
Some of it isn't bad design; some of it really is Perl being crappy. For example, the module needs to maintain two caches for each function, rather than one, because every Perl function can have a list context return value and a scalar context return value, which are different.
I'd say that about 2/3 of the crappiness of the module is the author's fuckups, and 1/3 is Perl's fault.
2006-07-25 09:39 am (UTC)
def memoized(file)
if File.exist?(file)
return Marshal.load(IO.read(file))
else
retval = yield
File.open(file, 'w') {|f|
f.print(Marshal.dump(retval))
}
retval
end
end
Caveat of singleton method
(Anonymous)
2006-07-25 03:38 pm (UTC)
2006-07-25 07:48 pm (UTC)
new journal, dont ask why.
there is a purpose though - possibly not very appealing though.
2008-07-16 07:54 am (UTC)