Brian Buckley wrote:
> Hello all,
>
> Using Memoize gem 1.2.0, memoizing TO a file appears to be working for me
> but subsequently reading that file (say, by rerunning the same script)
> appears NOT to be working  (the fib(n) calls are being run again).
> Inspecting the Memoize module I changed the line
>
> cache = Hash.new.update(Marshal.load(File.read(file))) rescue { }
> to
> cache = Hash.new.update(Marshal.load(File.read(file)))
>
> and it instead of silently failing I now see the error message: "in `load':
> marshal data too short (ArgumentError)"
>
> My questions:
> 1  What is causing this error? (possibly Windows related?)

That is odd.  I've run it on Windows with no trouble in the past.  Is
it possible you ran this program using 1.8.2, downloaded 1.8.4, then
re-ran the same code using the same cache?  It would fail with that
error if such is the case, since Marshal is not compatible between
versions of Ruby - not even minor versions.

> 2  What is the purpose of the rescue{} suppressing the error info in the
> first place?

The assumption (whoops!) was that if Hash.new.update failed it was
because there was no cache (i.e. first run), so just return an empty
hash.

> 3  Instead of using Marshall would using yaml be a reasonable alternative?
> (I am thinking of readability of the cache file and also capability to
> pre-populate it)

It will be slower, but it would work.

Regards,

Dan