Memoize.jl
Memoize.jl copied to clipboard
LRU example doesn't work
Forgive me if I'm missing something obvious...
julia> using Memoize, LRUCache
(@v1.4) pkg> status Memoize LRUCache
Status `~/.julia/environments/v1.4/Project.toml`
[8ac3fa9e] LRUCache v1.1.0
[c03570c3] Memoize v0.4.3
julia> @memoize LRU{Tuple{Any,Any},Any}(maxsize=2) function x(a, b)
println("Running")
a + b
end
ERROR: LoadError: MethodError: objects of type LRU{Tuple{Any,Any},Any} are not callable
Stacktrace:
[1] top-level scope at REPL[12]:1
[2] eval(::Module, ::Any) at ./boot.jl:331
[3] @memoize(::LineNumberNode, ::Module, ::Vararg{Any,N} where N) at /Users/fred/.julia/packages/Memoize/V4Yuh/src/Memoize.jl:51
in expression starting at REPL[12]:1
I guess this package isn't being maintained? For other users, the simple fix is just to wrap the LRU initialization in an anonymous function:
@memoize (() -> LRU{Tuple{Any,Any},Any}(maxsize=2)) function x(a, b)
println("Running")
a + b
end
also https://github.com/JuliaCollections/LRUCache.jl/issues/18 the packages don't seem to be actively maintained? @kmsquire ?
I think this was fixed, works for me now:
julia> @memoize LRU{Tuple{Any,Any},Any}(maxsize=2) function x(a, b)
println("Running")
a + b
end
x (generic function with 1 method)
julia> x(1,2)
Running
3