コード例 #1
0
        /// <inheritdoc />
        public sealed override async Task OnInvokeAsync(MethodInterceptionArgs args)
        {
            if (this.cache == null)
            {
                this.cache = CacheManager.GetCache(this.cacheName);
                if (this.cache == null)
                {
                    LogManager.GetCurrentClassLogger().Warn($"AOP cache [{this.cacheName}] is not initialized, define NoCache if needed!");
                }
            }

            var cacheToUse = this.cache;

            if (!cacheToUse.IsUseable())
            {
                await base.OnInvokeAsync(args).ConfigureAwait(false);

                return;
            }

            var key    = GetCacheKey(args);
            var result = await cacheToUse
                         .GetAsync(key, async() =>
            {
                await base.OnInvokeAsync(args).ConfigureAwait(false);
                return(args.ReturnValue);
            })
                         .ConfigureAwait(false);

            var returnType = GetReturnType(args.Method);

            args.ReturnValue = SafeCasting.CastTo(returnType, result);
        }
コード例 #2
0
        public sealed override void OnInvoke(MethodInterceptionArgs args)
        {
            if (this.cache == null)
            {
                this.cache = CacheManager.GetCache(this.cacheName);
                if (this.cache == null)
                {
                    LogManager.GetCurrentClassLogger().Warn($"AOP cache [{this.cacheName}] is not initialized, define NoCache if needed!");
                }
            }

            var cacheToUse = this.cache;

            if (!cacheToUse.IsUseable())
            {
                base.OnInvoke(args);
                return;
            }

            var key        = GetCacheKey(args);
            var result     = cacheToUse.Get <object>(key, () => { base.OnInvoke(args); return(args.ReturnValue); });
            var returnType = GetReturnType(args.Method);

            args.ReturnValue = SafeCasting.CastTo(returnType, result);
        }
コード例 #3
0
        public sealed override void OnInvoke(MethodInterceptionArgs args)
        {
            if (Interlocked.Read(ref initialized) == 0L)
            {
                this.cache = CacheManager.GetCache(this.cacheName);
                Interlocked.Exchange(ref initialized, 1L);
            }

            var cacheToUse = this.cache;

            if (cacheToUse == null)
            {
                base.OnInvoke(args);
                return;
            }

            var key        = GetCacheKey(args);
            var result     = cacheToUse.Get <object>(key, () => { base.OnInvoke(args); return(args.ReturnValue); });
            var returnType = GetReturnType(args.Method);

            args.ReturnValue = SafeCasting.CastTo(returnType, result);
        }
コード例 #4
0
        /// <inheritdoc />
        public sealed override async Task OnInvokeAsync(MethodInterceptionArgs args)
        {
            if (Interlocked.Read(ref initialized) == 0L)
            {
                this.cache = CacheManager.GetCache(this.cacheName);
                Interlocked.Exchange(ref initialized, 1L);
            }

            var cacheToUse = this.cache;

            if (cacheToUse == null)
            {
                await base.OnInvokeAsync(args);
            }
            else
            {
                var key    = GetCacheKey(args);
                var result = await cacheToUse.GetAsync(key, async() => { await base.OnInvokeAsync(args); return(args.ReturnValue); });

                var returnType = GetReturnType(args.Method);
                args.ReturnValue = SafeCasting.CastTo(returnType, result);
            }
        }