Skip to content

Commit 29eee6d

Browse files
feat: add an always-present mutable cache key to the system
1 parent dd8b432 commit 29eee6d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/systems/abstractsystem.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,11 @@ has_equations(::AbstractSystem) = true
805805
806806
Invalidate cached jacobians, etc.
807807
"""
808-
invalidate_cache!(sys::AbstractSystem) = sys
808+
function invalidate_cache!(sys::AbstractSystem)
809+
has_metadata(sys) || return sys
810+
empty!(getmetadata(sys, MutableCacheKey, nothing))
811+
return sys
812+
end
809813

810814
function Setfield.get(obj::AbstractSystem, ::Setfield.PropertyLens{field}) where {field}
811815
getfield(obj, field)

src/systems/system.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ end
88

99
const MetadataT = Base.ImmutableDict{DataType, Any}
1010

11+
abstract type MutableCacheKey end
12+
13+
const MutableCacheT = Dict{DataType, Any}
14+
1115
"""
1216
$(TYPEDEF)
1317
@@ -407,6 +411,7 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = [];
407411
end
408412
metadata = meta
409413
end
414+
metadata = Base.ImmutableDict(metadata, MutableCacheKey => MutableCacheT())
410415
System(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)), eqs, noise_eqs, jumps, constraints,
411416
costs, consolidate, dvs, ps, brownians, iv, observed, Equation[],
412417
var_to_name, name, description, defaults, guesses, systems, initialization_eqs,

0 commit comments

Comments
 (0)