Skip to content

Commit

Permalink
Add dememoize function for restarting cache store
Browse files Browse the repository at this point in the history
  • Loading branch information
djsegal committed Jun 11, 2017
1 parent 1c920e0 commit f9758e2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Memoize.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Memoize
export @memoize
export @memoize, dememoize
using Compat

macro memoize(args...)
Expand Down Expand Up @@ -106,3 +106,19 @@ macro memoize(args...)
end)
end
end

function dememoize()

mod = current_module()

all_caches = filter( x ->
startswith(string(x), "##") &&
endswith(string(x),"_memoized_cache"),
names(mod, true)
)

for cur_cache_symbol in all_caches
empty!(getfield(mod, cur_cache_symbol))
end

end
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,21 @@ end
outer()
@test !isdefined(:inner)

run = 0
@memoize function repeat(a::Int)
global run += 1
a
end
@test repeat(3) == 3
@test run == 1
@test repeat(3) == 3
@test run == 1
dememoize()
@test repeat(3) == 3
@test run == 2
@test repeat(3) == 3
@test run == 2

if VERSION >= v"0.5.0-dev+5235"
@memoize function typeinf(x)
x + 1
Expand Down

0 comments on commit f9758e2

Please sign in to comment.