Memoize.jl icon indicating copy to clipboard operation
Memoize.jl copied to clipboard

LRU example doesn't work

Open fredcallaway opened this issue 5 years ago • 2 comments

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

fredcallaway avatar Jul 24 '20 18:07 fredcallaway

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

fredcallaway avatar Aug 27 '20 03:08 fredcallaway

also https://github.com/JuliaCollections/LRUCache.jl/issues/18 the packages don't seem to be actively maintained? @kmsquire ?

kalmarek avatar Sep 23 '20 07:09 kalmarek

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

ericphanson avatar Nov 20 '23 22:11 ericphanson