GetCacheDataFromObject and GetObjectFromCacheData
which unfortunatly has also been disabled in .NET 5
System.NotSupportedException: 'BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.'
Code: Select all
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
at Stimulsoft.Report.Web.StiCacheHelper.DataSerializer.Serialize(Object obj)
at Stimulsoft.Report.Web.StiCacheHelper.GetCacheDataFromObject(Object obj)
Code: Select all
public class StiRedisCache : StiCacheHelper
{
private readonly CacheService _cache;
public StiRedisCache(CacheService cache)
{
_cache = cache;
}
public override object GetObject(string guid)
{
var uid = HttpContext.CoreHttpContext.User.UserId();
var key = $"stimulsoft.{uid:D}.{guid}";
var item = _cache.Database.StringGet(key);
if (item == RedisValue.Null)
return null;
return GetObjectFromCacheData(Convert.FromBase64String(item));
}
public override void SaveObject(object obj, string guid)
{
var uid = HttpContext.CoreHttpContext.User.UserId();
var key = $"stimulsoft.{uid:D}.{guid}";
_cache.Database.StringSet(key,
Convert.ToBase64String(GetCacheDataFromObject(obj)),
TimeSpan.FromMinutes(10));
}
}