2
Redisを使用して.NETコアに分散キャッシュを設定しようとしています。.NETコアの分散キャッシュ(Redis)
私はそれを実装することができますが、私はPOCOオブジェクトを格納する方法を考え出すのに問題があります。
私が見たすべての例では、文字列の格納と検索を行っています。
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;
}
}
私はjsonのオブジェクトをシリアル化して文字列を格納する必要があると仮定しますか?別の方法がない限り。
ありがとうございました!
私は同じ結論に達しました。オブジェクトをjsonとしてシリアル化する必要があります。 – Seb