-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Public/documented API to get cache contents #26
Comments
Thanks, yea I should document this. |
@marius311 julia> @memoize f(x) = x^3
f (generic function with 1 method)
julia> f(111)
1367631
julia> f(222)
10941048
julia> Memoization.find_caches(f)
IdDict{Any, Any} with 1 entry:
f => IdDict{Any, Any}(((222,), ())=>10941048, ((111,), ())=>1367631)
julia> Memoization.find_caches(f)[f]
IdDict{Any, Any} with 2 entries:
((222,), ()) => 10941048
((111,), ()) => 1367631
I’m not sure if this |
Thanks for checking, yea the reason it returns that is because for memoizing callables/closures each instance gets its own entry, like: julia> struct Foo x end
julia> @memoize (f::Foo)() = f.x
julia> Foo(1)()
1
julia> Foo(2)()
2
julia> Memoization.find_caches(Foo)
IdDict{Any, Any} with 2 entries:
Foo(2) => IdDict{Any, Any}(((), ())=>2)
Foo(1) => IdDict{Any, Any}(((), ())=>1) User-facing should definitely have a version that returns the single cache (if there is only one). Will try to get to this soon. |
It would be nice to have a clear way to get a function’s cache. I see there are functions
get_cache()
,get_caches()
, andfind_caches()
,Memoization.jl/src/Memoization.jl
Line 30 in 7d183e2
Memoization.jl/src/Memoization.jl
Line 50 in 7d183e2
Memoization.jl/src/Memoization.jl
Line 81 in 7d183e2
but it’s not clear if they’re part of a public API, how to use them, or how they differ. The thing I’d use it for would be a to write the cache to disk (in some sense a workaround for #4), but I’m sure there are other uses.
The text was updated successfully, but these errors were encountered: