Skip to content

Commit

Permalink
Merge a656b79 into 88cd11b
Browse files Browse the repository at this point in the history
  • Loading branch information
Corneliu Cofaru committed Sep 12, 2018
2 parents 88cd11b + a656b79 commit 8c73b94
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/diskcache.jl
Expand Up @@ -32,8 +32,13 @@ end

# Show method
show(io::IO, dc::DiskCache) = begin
println(io, "Disk cache for \"$(dc.memcache.name)\" " *
"with $(length(dc.memcache.cache)) entries, $(length(dc.offsets)) on disk.")
_msz = length(dc.memcache.cache)
_dsz = length(dc.offsets)
_tsz = length(symdiff(keys(dc.memcache.cache), keys(dc.offsets))) +
length(intersect(keys(dc.memcache.cache), keys(dc.offsets)))
_en = ifelse(_msz == 1, "entry", "entries")
println(io, "$(dc.memcache.name) " *
"(disk cache with $_tsz $_en, $_dsz on disk)")
end


Expand Down
17 changes: 13 additions & 4 deletions src/memcache.jl
Expand Up @@ -15,9 +15,16 @@ MemoryCache(f::T where T<:Function;
MemoryCache(name, f, Dict{input_type, output_type}())


function hashes(args...; kwargs...)
_h1 = hash(hash(arg)+hash(typeof(arg)) for arg in args)
_h2 = hash(hash(kwarg) for kwarg in kwargs)
return hash(_h1 + _h2)
end


# Call method
(mc::T where T<:MemoryCache)(args...; kwargs...) = begin
_hash = hash([map(hash, args)..., map(hash, collect(kwargs))...])
_hash = hashes(args...; kwargs...)
if _hash in keys(mc.cache)
out = mc.cache[_hash]
else
Expand All @@ -30,9 +37,11 @@ end


# Show method
show(io::IO, c::MemoryCache) = begin
println(io, "Memory cache for \"$(c.name)\" " *
"with $(length(c.cache)) entries.")
show(io::IO, mc::MemoryCache) = begin
_msz = length(mc.cache)
_en = ifelse(_msz == 1, "entry", "entries")
println(io, "$(mc.name) " *
"(memory cache with $_msz $_en)")
end


Expand Down

0 comments on commit 8c73b94

Please sign in to comment.