Skip to content

Commit 95c7465

Browse files
committed
fix: litedb with data retriever fails when cache null is true
1 parent 0768637 commit 95c7465

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/EasyCaching.LiteDB/DefaultLiteDBCachingProvider.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,27 @@ public override CacheValue<T> BaseGet<T>(string cacheKey, Func<T> dataRetriever,
127127
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
128128
ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration));
129129

130-
var result = BaseGet<T>(cacheKey);
131-
132-
if (result.HasValue)
130+
var cacheItem = _cache.FindOne(c => c.cachekey == cacheKey && c.expiration > DateTimeOffset.Now.ToUnixTimeSeconds());
131+
132+
if (cacheItem != null)
133133
{
134-
return result;
134+
if (_options.EnableLogging)
135+
_logger?.LogInformation($"Cache Hit : cachekey = {cacheKey}");
136+
137+
CacheStats.OnHit();
138+
139+
return new CacheValue<T>(Newtonsoft.Json.JsonConvert.DeserializeObject<T>(cacheItem.cachevalue), true);
135140
}
136141

137142
var item = dataRetriever();
138143

139144
if (item != null || _options.CacheNulls)
140145
{
141146
Set(cacheKey, item, expiration);
142-
result = new CacheValue<T>(item, true);
143-
}
144-
145-
return result;
147+
return new CacheValue<T>(item, true);
148+
}
149+
150+
return CacheValue<T>.NoValue;
146151
}
147152

148153
/// <summary>

0 commit comments

Comments
 (0)