Skip to content

Commit e7dba37

Browse files
Merge pull request #69 from JuliaComputing/as/fix-unhack-sys
refactor: use mutable cache API for `unhack_system`
2 parents 6089a52 + bf8d759 commit e7dba37

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

lib/ModelingToolkitTearing/src/ModelingToolkitTearing.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ include("reassemble.jl")
5757

5858
struct UnhackSystemCacheKey end
5959

60+
function MTKBase.should_invalidate_mutable_cache_entry(::Type{UnhackSystemCacheKey}, patch::NamedTuple)
61+
return true
62+
end
63+
6064
function MTKBase.unhack_system(sys::System)
61-
cache = getmetadata(sys, MTKBase.MutableCacheKey, nothing)
62-
if cache isa MTKBase.MutableCacheKey
63-
cached_sys = get(cache, UnhackSystemCacheKey, nothing)
64-
if cached_sys isa System
65-
return cached_sys
66-
end
65+
cached_sys = MTKBase.check_mutable_cache(sys, UnhackSystemCacheKey, System, nothing)
66+
if cached_sys isa System
67+
return cached_sys
6768
end
6869
# Observed are copied by the masking operation
6970
obseqs = observed(sys)
@@ -173,9 +174,7 @@ function MTKBase.unhack_system(sys::System)
173174
@set! newsys.unknowns = dvs
174175
@set! newsys.schedule = sched
175176

176-
if cache isa MTKBase.MutableCacheT
177-
cache[UnhackSystemCacheKey] = newsys
178-
end
177+
MTKBase.store_to_mutable_cache!(sys, UnhackSystemCacheKey, newsys)
179178

180179
return newsys
181180
end

0 commit comments

Comments
 (0)