1
Setting
I created a function using AOP to cache information, when the method is called I store in Redis using the cache.StringSet
, but when I need to capture back the value of Redis I need it to come back of the same type that I received, I don’t know if I’m doing it right Saving and storing the string, but when I return from Redis cache.StringGet
I need it to be the same type when the object was inserted.
Remembering that objects can vary, they can be of N different types.
Code
public sealed override void OnInvoke(MethodInterceptionArgs args)
{
var cache = RedisConnectorHelper.Connection.GetDatabase();
var result = cache.StringGet(args.Method.Name);
if (result.HasValue)
{
args.ReturnValue = result;
return;
}
base.OnInvoke(args);
cache.StringSet(args.Method.Name, Serialize(args.ReturnValue));
}
private string Serialize(object obj)
{
return JsonConvert.SerializeObject(obj);
}