Skip to content

klaff/Memoize.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Memoize.jl

Build Status Coverage Status

Easy memoization for Julia.

Usage

using Memoize
@memoize function x(a)
	println("Running")
	a
end
julia> x(1)
Running
1

julia> x(1)
1

By default, Memoize.jl uses an ObjectIdDict as a cache, but it's also possible to specify the type of the cache. If you want to cache vectors based on the values they contain, you probably want this:

using Memoize
@memoize Dict function x(a)
	println("Running")
	a
end

You can also specify the full function call for constructing the dictionary. For example, to use LRUCache.jl:

using Memoize
using LRUCache
@memoize LRU{Tuple{Any,Any},Any}(maxsize=2) function x(a, b)
    println("Running")
    a + b
end
julia> x(1,2)
Running
3

julia> x(1,2)
3

julia> x(2,2)
Running
4

julia> x(2,3)
Running
5

julia> x(1,2)
Running
3

julia> x(2,3)
5

About

@memoize macro for Julia

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Julia 100.0%