. Net Ядро получает данные объекта с помощью ServiceStack.Redis RedisClient Class? - PullRequest
0 голосов
/ 09 февраля 2020

Я использовал кэш-память в своем проекте, и кэш-память работала совместимо с установленной системой. Но я остановился на Redis Cache. Возвращает значение строкового типа для кэша Redis, а не объекта функции RedisClient.get. Я перепробовал много методов JsonConvert.Deserialize et c, но это не сработало. Как вернуть значение типа объекта с RedisClient?

Сообщение об ошибке

System.InvalidCastException
Unable to cast object of type 'System.String' to type           
'[AhiCommerce.Core.Utilities.Result.IDataResult`1[System.Collections.Generic.List`1[Entities.Concrete.Product]]]'. 

DataResult.cs

public class DataResult<T> : Result, IDataResult<T>
{
    public DataResult(T data,bool success, string message) : base(success, message)
    {
        Data = data;
    }

    public DataResult(T data, bool success):base(success)
    {
        Data = data;
    }

    public T Data { get; }
}

ProductManager.cs

    [PerformanceAspect(5)]
    [CacheAspect(duration:1)]
    public IDataResult<List<Product>> GetList()
    {
        return new SuccessDataResult<List<Product>>(_productDal.GetList().ToList());
    }

RedisCacheManager.cs

    public object Get(string key)
    {
        return _cache.GetValues(key);
    }


    }

CacheAspect.cs

    public class CacheAspect:MethodInterception
{
    private int _duration;
    private ICacheManager _cacheManager;

    public CacheAspect(int duration=60)
    {
        _duration = duration;
        _cacheManager = ServiceTool.ServiceProvider.GetService<ICacheManager>();
    }

    public override void Intercept(IInvocation invocation)
    {
        var methodName = string.Format($"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}");
        var arguments = invocation.Arguments.ToList();
        var key = $"{methodName}({string.Join(",",arguments.Select(x=>x?.ToString()??"<Null>"))})";
        if (_cacheManager.IsAdd(key))
        {
            invocation.ReturnValue = _cacheManager.Get(key);
            return;
        }
        invocation.Proceed();
        _cacheManager.Add(key,invocation.ReturnValue,_duration);
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...