public static async Task SetString(this IKeyValueCache cache, string key, string str, DateTime?expiresIn = null) { if (str == null) { await cache.Remove(key); } else { var bytes = Encoding.UTF8.GetBytes(str); await cache.SetBytes(key, bytes, expiresIn); } }