Пример #1
0
        static StructCacheInvalidator()
        {
            var dynamicMethod = new DynamicMethod
                                (
                nameof(Invalidate),
                typeof(void),
                new[] { typeof(InvalidateDelegateType).GetMethod("Invoke").GetParameters()[0].ParameterType },
                typeof(T).GetTypeInfo().Module
                                );

            var ilGenerator = dynamicMethod.GetILGenerator();

            CacheInvalidator.GenerateInvalidateIL <T>(ilGenerator);
            invalidateDelegate = (InvalidateDelegateType)dynamicMethod.CreateDelegate(typeof(InvalidateDelegateType));
        }
Пример #2
0
 /// <summary>
 /// Invalidates all the instances of type <see cref="ICache" /> which are fields of
 /// class given as root object and any fields of the same type in child fields recursively.
 /// Use it when there are massive changes and all the caches need to be invalidated.
 /// </summary>
 /// <param name="root">Root object from which we recursively drop the caches.</param>
 public static void InvalidateCaches <T>(T?root)
     where T : class
 {
     CacheInvalidator <T> .Invalidate(root);
 }