public void InvalidateTable([FromBody] InvalidateTableRequest req) { if (CacheLogic.ServerBroadcast is not SimpleHttpBroadcast sci) { throw new InvalidOperationException("CacheInvalidator is not a SimpleHttpCacheInvalidator"); } sci.InvalidateTable(req); }
//Called from Controller public void InvalidateTable(InvalidateTableRequest request) { if (this.bordcastSecretHash != request.SecretHash) { throw new InvalidOperationException("invalidationSecret does not match"); } if (request.OriginMachineName == Environment.MachineName && request.OriginApplicationName == Schema.Current.ApplicationName) { return; } Receive?.Invoke(request.MethodName, request.Argument); }
public void Send(string methodName, string argument) { var request = new InvalidateTableRequest { MethodName = methodName, Argument = argument, SecretHash = this.bordcastSecretHash, OriginMachineName = Environment.MachineName, OriginApplicationName = Schema.Current.ApplicationName, }; foreach (var url in broadcastUrls) { string?errorBody = null; try { var fullUrl = url.TrimEnd('/') + "/api/cache/invalidateTable"; var json = JsonContent.Create(request, options: EntityJsonContext.FullJsonSerializerOptions /*SignumServer.JsonSerializerOptions*/); var response = client.PostAsync(fullUrl, json).Result; if (!response.IsSuccessStatusCode) { errorBody = response.Content.ReadAsStringAsync().Result; } } catch (Exception e) { e.LogException(a => { a.ControllerName = nameof(SimpleHttpBroadcast); a.Data.Text = errorBody; }); } } }