Skip to content

Commit

Permalink
Merge pull request grandnode#740 from Leonardo-Ferreira/ignoreDefault…
Browse files Browse the repository at this point in the history
…Values

Ignore default values
  • Loading branch information
Krzysztof Pajak authored Jan 6, 2020
2 parents bfc9a39 + 731a33b commit 743243c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions Grand.Core/Caching/DistributedRedisCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public partial class DistributedRedisCache : ICacheManager
{
private readonly IDatabase _distributedCache;
private readonly IConnectionMultiplexer _connectionMultiplexer;
private static readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore };

public DistributedRedisCache(string redisConnectionString)
{
Expand Down Expand Up @@ -60,6 +61,7 @@ public T Get<T>(string key)
return (JsonConvert.DeserializeObject<T>(res), true);
}
}

public (T Result, bool FromCache) TryGetValue<T>(string key)
{
var res = _distributedCache.StringGet(key);
Expand All @@ -73,7 +75,6 @@ public T Get<T>(string key)
}
}


public virtual async Task RemoveAsync(string key)
{
await _distributedCache.KeyDeleteAsync(key, CommandFlags.PreferMaster);
Expand All @@ -85,7 +86,7 @@ public virtual async Task SetAsync(string key, object data, int cacheTime)
return;

//serialize item
var serializedItem = JsonConvert.SerializeObject(data);
var serializedItem = JsonConvert.SerializeObject(data, _jsonSettings);

//and set it to cache
await _distributedCache.StringSetAsync(key, serializedItem, TimeSpan.FromMinutes(cacheTime), When.Always, CommandFlags.FireAndForget);
Expand All @@ -97,11 +98,12 @@ public void Set(string key, object data, int cacheTime)
return;

//serialize item
var serializedItem = JsonConvert.SerializeObject(data);
var serializedItem = JsonConvert.SerializeObject(data, _jsonSettings);

//and set it to cache
_distributedCache.StringSet(key, serializedItem, TimeSpan.FromMinutes(cacheTime), When.Always, CommandFlags.FireAndForget);
}

public bool IsSet(string key)
{
return _distributedCache.KeyExists(key);
Expand Down Expand Up @@ -136,10 +138,5 @@ public virtual void Dispose()
{
//nothing special
}





}
}

0 comments on commit 743243c

Please sign in to comment.