marius311 / Memoization.jl

Easily and efficiently memoize any function, closure, or callable object in Julia.
MIT License
99 stars 2 forks source link

MethodError: objects of type (...) are not callable #27

Closed Omar-Elrefaei closed 1 year ago

Omar-Elrefaei commented 1 year ago

Hi, Thanks for the awesome package. It really made some workflow yesterday quite smooth when I needed to iterate over the "presentation" of some dataframe but it'd have been quite painful to decouple that from the heavy computation for such a small one-off script. Used it nicely with ThreadSafeDict.

But when things were accumulating too much in memory I was looking at LRUCache, but I've been getting:

julia> @memoize LRU(maxsize=5) function mycond(x)
            println(x);
            return cond(x)
       end
ERROR: MethodError: objects of type LRU{Matrix{Float64}, Float64} are not callable
Stacktrace:
 [1] #s44#53
   @ C:\Users\elom\.julia\packages\Memoization\xgAKx\src\Memoization.jl:173 [inlined]
 [2] var"#s44#53"(::Any, #unused#::Any)
   @ Main .\none:0
 [3] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any})
   @ Core .\boot.jl:580
 [4] get_caches()
   @ Memoization C:\Users\elom\.julia\packages\Memoization\xgAKx\src\Memoization.jl:58
 [5] find_caches(func::typeof(_cond12))
   @ Memoization C:\Users\elom\.julia\packages\Memoization\xgAKx\src\Memoization.jl:81
 [6] empty_cache!(func::Function)
   @ Memoization C:\Users\elom\.julia\packages\Memoization\xgAKx\src\Memoization.jl:80
 [7] top-level scope
   @ C:\Users\elom\.julia\packages\Memoization\xgAKx\src\Memoization.jl:180

I've skimmed #4 and when you said

Ok, so syntax like @memoize DiskDict("foo.dat") foo(x) = .... now works on master.

That doesn't seem to be the case anymore. Maybe there was a recent regression? in fact I get the same error when I try your JLD2BackedDicts example.

Note: I am using v0.2 and Julia v1.7.2

marius311 commented 1 year ago

Sorry for the super late reply but I just tried this and it looks to be working on 0.2.1 (currently the latest version).