diff --git a/slac_timing/buffer.py b/slac_timing/buffer.py index 65ec5cc..ae1d6d5 100644 --- a/slac_timing/buffer.py +++ b/slac_timing/buffer.py @@ -84,6 +84,7 @@ def _clear_ca_cache(self) -> None: return suffix = f"HST{self.number}" + stale_pvids = [ pvid for pvid in list(_PVcache_) if pvid[0].endswith(suffix) @@ -96,6 +97,18 @@ def _clear_ca_cache(self) -> None: except BaseException: pass + context_cache = epics.ca._cache.get(ctx) + if context_cache is None: + return + stale_names = [name for name in context_cache if name.endswith(suffix)] + for name in stale_names: + entry = context_cache.get(name) + if entry is not None and getattr(entry, "chid", None) is not None: + try: + epics.ca.clear_channel(entry.chid) + except BaseException: + context_cache.pop(name, None) + def is_reserved(self) -> bool: return self.number is not None and self.number != 0