JuliaCollections / LRUCache.jl

An implementation of an LRU Cache in Julia
Other
56 stars 23 forks source link

interaction with Memoize #18

Closed kalmarek closed 11 months ago

kalmarek commented 4 years ago

I get

julia> using Memoize

julia> using LRUCache

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[8]:1
 [2] eval(::Module, ::Any) at ./boot.jl:331
 [3] @memoize(::LineNumberNode, ::Module, ::Vararg{Any,N} where N) at /home/kalmar/.julia/packages/Memoize/V4Yuh/src/Memoize.jl:51
in expression starting at REPL[8]:1

maybe it'd be a good idea to add LRUCache to [Extras] in Memoize.jl? EDIT:

(tmp) pkg> st
Status `/tmp/Project.toml`
  [8ac3fa9e] LRUCache v1.1.0
  [c03570c3] Memoize v0.4.3

julia> versioninfo()
Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 2
kalmarek commented 4 years ago

ok, this issue should probably go to Memoize.jl as it tries to call the first argument in @memoize macro, but now the maxsize keyword is obligatory:

julia> lru = LRU{Tuple{Any,Any},Any}(;maxsize=2)
LRU{Tuple{Any,Any},Any} with 0 entries

julia> @memoize ()->lru function x(a, b)

           println("Running")

           a + b

       end
x (generic function with 1 method)

julia> x(2,3)
Running
5

julia> x(2,3)
5
ericphanson commented 11 months ago

this works now (https://github.com/JuliaCollections/Memoize.jl/issues/58#issuecomment-1819934099)