public override void AttachInvalidations(SchemaBuilder sb, InvalidateWith invalidateWith, EventHandler invalidate) { if (CacheLogic.GloballyDisabled) { base.AttachInvalidations(sb, invalidateWith, invalidate); } else { void onInvalidation(object?sender, CacheEventArgs args) { if (args == CacheEventArgs.Invalidated) { invalidate(sender, args); } else if (args == CacheEventArgs.Disabled) { if (Transaction.InTestTransaction) { invalidate(sender, args); Transaction.Rolledback += dic => invalidate(sender, args); } Transaction.PostRealCommit += dic => invalidate(sender, args); } } foreach (var t in invalidateWith.Types) { CacheLogic.TryCacheTable(sb, t); GetController(t).Invalidated += onInvalidation; } } }
public virtual void AttachInvalidations(SchemaBuilder sb, InvalidateWith invalidateWith, EventHandler invalidate) { isUsed = true; Action onInvalidation = () => { if (Transaction.InTestTransaction) { invalidate(this, null); Transaction.Rolledback += dic => invalidate(this, null); } Transaction.PostRealCommit += dic => invalidate(this, null); }; Schema schema = sb.Schema; foreach (var type in invalidateWith.Types) { giAttachInvalidations.GetInvoker(type)(schema, onInvalidation); } var dependants = DirectedGraph <Table> .Generate(invalidateWith.Types.Select(t => schema.Table(t)), t => t.DependentTables().Select(kvp => kvp.Key)).Select(t => t.Type).ToHashSet(); dependants.ExceptWith(invalidateWith.Types); foreach (var type in dependants) { giAttachInvalidationsDependant.GetInvoker(type)(schema, onInvalidation); } }
public ResetLazy <T> GlobalLazy <T>(Func <T> func, InvalidateWith invalidateWith) where T : class { var result = Signum.Engine.GlobalLazy.WithoutInvalidations(() => { GlobalLazyManager.OnLoad(this, invalidateWith); return(func()); }); GlobalLazyManager.AttachInvalidations(this, invalidateWith, (sender, args) => result.Reset()); return(result); }
public override void OnLoad(SchemaBuilder sb, InvalidateWith invalidateWith) { if (CacheLogic.GloballyDisabled) { base.OnLoad(sb, invalidateWith); } else { foreach (var t in invalidateWith.Types) { sb.Schema.CacheController(t) !.Load(); } } }
public ResetLazy <T> GlobalLazy <T>(Func <T> func, InvalidateWith invalidateWith, Action onInvalidated = null, LazyThreadSafetyMode mode = LazyThreadSafetyMode.ExecutionAndPublication) where T : class { var result = Signum.Engine.GlobalLazy.WithoutInvalidations(() => { GlobalLazyManager.OnLoad(this, invalidateWith); return(func()); }); GlobalLazyManager.AttachInvalidations(this, invalidateWith, (sender, args) => { result.Reset(); onInvalidated?.Invoke(); }); return(result); }
public virtual void OnLoad(SchemaBuilder sb, InvalidateWith invalidateWith) { }