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?)
2 What is the purpose of the rescue{} suppressing the error info in the
first place?
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)
Thanks.
-- Brian Buckley
···
------------------------------------------
require 'memoize'
include Memoize
def fib(n)
puts "running... n is #{n}"
return n if n < 2
fib(n-1) + fib(n-2)
end
h = memoize(:fib,"fib.cache")
puts fib(10)