示例#1
0
        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;
                }
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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);
        }
示例#4
0
 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();
         }
     }
 }
示例#5
0
        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);
        }
示例#6
0
 public virtual void OnLoad(SchemaBuilder sb, InvalidateWith invalidateWith)
 {
 }