Skip to content

Commit b93391e

Browse files
committed
Improve cache ambig. related method errors
1 parent 01b3d0d commit b93391e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/RecoPlans/Cache.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ Base.@kwdef mutable struct ProcessResultCache{P <: AbstractImageReconstructionPa
44
const maxsize::Int64 = 1
55
cache::LRU{UInt64, Any} = LRU{UInt64, Any}(maxsize = maxsize)
66
end
7-
function process(algo::Union{A, Type{<:A}}, param::ProcessResultCache, inputs...) where {A<:AbstractImageReconstructionAlgorithm}
7+
process(algo::A, param::ProcessResultCache, inputs...) where {A <: AbstractImageReconstructionAlgorithm} = hashed_process(algo, param, inputs...)
8+
process(algoT::Type{<:A}, param::ProcessResultCache, inputs...) where {A <: AbstractImageReconstructionAlgorithm} = hashed_process(algoT, param, inputs...)
9+
10+
function hashed_process(algo, param::ProcessResultCache, inputs...)
811
id = hash(param.param, hash(inputs, hash(algo)))
912
result = get!(param.cache, id) do
1013
process(algo, param.param, inputs...)
@@ -28,9 +31,14 @@ function clear!(plan::RecoPlan{<:ProcessResultCache}, preserve::Bool = true)
2831
return plan
2932
end
3033

31-
function validvalue(plan, ::Type{T}, value::RecoPlan{<:ProcessResultCache}) where T
34+
function validvalue(plan, union::Type{Union{T, ProcessResultCache{<:T}}}, value::RecoPlan{ProcessResultCache}) where T
35+
innertype = value.param isa RecoPlan ? typeof(value.param).parameters[1] : typeof(value.param)
36+
return ProcessResultCache{<:innertype} <: union
37+
end
38+
39+
function validvalue(plan, union::UnionAll, value::RecoPlan{ProcessResultCache})
3240
innertype = value.param isa RecoPlan ? typeof(value.param).parameters[1] : typeof(value.param)
33-
return ProcessResultCache{<:innertype} <: T
41+
return ProcessResultCache{<:innertype} <: union
3442
end
3543

3644
# Do not serialize cache and lock, only param

0 commit comments

Comments
 (0)