Skip to content

Commit

Permalink
Transparent getter/setter for caches
Browse files Browse the repository at this point in the history
  • Loading branch information
nHackel committed Nov 8, 2024
1 parent 662beda commit 91b6154
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/RecoPlans/Cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@ function clear!(plan::RecoPlan{<:ProcessResultCache}, preserve::Bool = true)
return plan
end

# Make cache transparent for property getter/setter
function Base.setproperty!(plan::RecoPlan{<:ProcessResultCache}, name::Symbol, value)
if in(name, [:param, :cache, :maxsize])
old = getproperty(plan, name)
setvalue!(plan, name, value)
getfield(plan, :setProperties)[name] = true
for listener in getlisteners(plan, name)
try
propertyupdate!(listener, plan, name, old, x)
catch e
@error "Exception in listener $listener " e
end
end
else
setproperty!(plan.param, name, value)
end
end
function Base.getproperty(plan::RecoPlan{<:ProcessResultCache}, name::Symbol)
if in(name, [:param, :cache, :maxsize])
return getfield(plan, :values)[name]
else
return getproperty(plan.param, name)
end
end

function validvalue(plan, ::Type{T}, value::RecoPlan{<:ProcessResultCache}) where T
innertype = value.param isa RecoPlan ? typeof(value.param).parameters[1] : typeof(value.param)
return ProcessResultCache{<:innertype} <: T
Expand Down

0 comments on commit 91b6154

Please sign in to comment.