Ejemplo n.º 1
0
        protected override void AfterRunMethod(IInvocation invocation)
        {
            var serviceMethod = invocation.MethodInvocationTarget ?? invocation.Method;

            if (!(serviceMethod.GetCustomAttributes(true)
                  .FirstOrDefault(x => x.GetType() == typeof(CacheOutputAttribute)) is CacheOutputAttribute
                  attribute))
            {
                return;
            }

            var cacheKey = _keyGenerator.GetCacheKey(serviceMethod, invocation.Arguments, attribute.CacheKeyPrefix);

            if (string.IsNullOrWhiteSpace(cacheKey) || invocation.ReturnValue == null)
            {
                return;
            }

            var value = invocation.ReturnValue;

            if (value.GetType().IsGenericType&& value.GetType().GetGenericTypeDefinition() == typeof(Task <>))
            {
                var result = value.GetType().GetProperty("Result")?.GetValue(value, null);
                cacheKey = _keyGenerator.GetCacheKey(serviceMethod, invocation.Arguments, attribute.CacheKeyPrefix, result?.GetType());
                value    = result;
            }

            _cacheMemory.Set(cacheKey, value, attribute.Expiration);
        }
Ejemplo n.º 2
0
        public async Task <RegisterUserResponse> CreateTestUser()
        {
            var res = await CreateUser(new RegisterUserRequest()
            {
                UserName  = "******",
                Password  = "******",
                FirstName = "Test",
                LastName  = "User",
            }, UserStatus.Active);

            BaseUserInfo user = null;

            if (res.Item1 == 0)
            {
                user = res.Item2.MapTo <BaseUserInfo>();
                await _cacheMemory.Set(user.Id.ToString(), user);
            }

            return(new RegisterUserResponse()
            {
                Status = res.Item1,
                UserInfo = user
            });
        }