I am trying to setup Distributed Cache in .NET Core using Redis.
I am able to get it implemented but I am having trouble figuring out how to store POCO objects.
In every example I've seen they are storing and retrieving strings. What about more complex data types:
public async Task<string> Get()
{
var cacheKey = "TheTime";
var existingTime = _distributedCache.GetString(cacheKey);
if (!string.IsNullOrEmpty(existingTime))
{
return "Fetched from cache : " + existingTime;
}
else
{
existingTime = DateTime.UtcNow.ToString();
_distributedCache.SetString(cacheKey, existingTime);
return "Added to cache : " + existingTime;
}
}
I assume I'll need to serialize the objects in json then store the strings? Unless there is another way.
Thank you!