using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services; using ZB.MOM.WW.ScadaBridge.Commons.Messages.Communication; namespace ZB.MOM.WW.ScadaBridge.InboundAPI; /// /// Applies a peer central node's to this node /// (ScadaBridge#103): drops the method's compiled handler, its known-bad compile record and its /// cached ApiMethod row, so the next request on this node reads the stored row and compiles /// it afresh. /// /// /// Compile state (#75) is per central node. Without this, a recompile on one node cleared the /// known-bad record only there: the peer kept refusing the method with /// SCRIPT_COMPILE_FAILED while its record matched the unchanged script text, because the /// per-request revision check only notices a changed script. The peer does not recompile eagerly; /// its next request (or its own recompile) compiles the current text. /// public sealed class InboundApiCacheInvalidationHandler : ICentralCacheInvalidationHandler { private readonly InboundScriptExecutor _executor; private readonly ApiMethodCache _methodCache; /// Creates the handler. /// This node's inbound script executor. /// This node's API-method row cache. public InboundApiCacheInvalidationHandler(InboundScriptExecutor executor, ApiMethodCache methodCache) { ArgumentNullException.ThrowIfNull(executor); ArgumentNullException.ThrowIfNull(methodCache); _executor = executor; _methodCache = methodCache; } /// public void Apply(ICentralCacheInvalidation invalidation) { if (invalidation is InboundApiMethodInvalidated { MethodName: { Length: > 0 } name }) { _executor.InvalidateMethod(name); _methodCache.Invalidate(name); } } }