You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixed a bug where get by id(s) with cache key would also set the id b… (#161)
* Fixed a bug where get by id(s) with cache key would also set the id based cache route when there was an include or exclude defined. Also ensure we look up by the cache key first.
* Update src/Foundatio.Repositories.Elasticsearch/Repositories/ElasticReadOnlyRepositoryBase.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Apply suggestion from @niemyjski
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
// NOTE: Custom cache keys store the complete filtered result, but ID-based caching is skipped when includes/excludes are present to avoid incomplete data.
973
+
// This method also doesn't take into account any query includes or excludes but GetById(s) requests don't specify a query.
varlog=await_dailyRepository.AddAsync(LogEventGenerator.Generate(companyId:"1234567890",message:"test",stuff:"stuff"), o =>o.ImmediateConsistency());
256
+
Assert.NotNull(log?.Id);
257
+
258
+
Assert.Equal(1,_cache.Misses);
259
+
Assert.Equal(0,_cache.Hits);
260
+
Assert.Equal(1,_cache.Writes);
261
+
Assert.Collection(_cache.Items, c =>Assert.StartsWith("alias:daily-logevents-",c.Key));
262
+
263
+
conststringcacheKey="company:1234567890";
264
+
varcompanyLog=await_dailyRepository.GetByIdAsync(log!.Id, o =>o.QueryLogLevel(LogLevel.Warning).Exclude(e =>e.Date).Include(e =>e.Id).Include("createdUtc").Cache(cacheKey));
Assert.Collection(_cache.Items, c =>Assert.StartsWith("alias:daily-logevents-",c.Key), c =>Assert.Equal($"LogEvent:{cacheKey}",c.Key));
275
+
276
+
// Ensure cache hit by cache key.
277
+
companyLog=await_dailyRepository.GetByIdAsync(log!.Id, o =>o.QueryLogLevel(LogLevel.Warning).Exclude(e =>e.Date).Include(e =>e.Id).Include("createdUtc").Cache(cacheKey));
varlog=await_dailyRepository.AddAsync(LogEventGenerator.Generate(companyId:"1234567890",message:"test",stuff:"stuff"), o =>o.ImmediateConsistency());
310
+
Assert.NotNull(log?.Id);
311
+
312
+
Assert.Equal(1,_cache.Misses);
313
+
Assert.Equal(0,_cache.Hits);
314
+
Assert.Equal(1,_cache.Writes);
315
+
Assert.Collection(_cache.Items, c =>Assert.StartsWith("alias:daily-logevents-",c.Key));
316
+
317
+
conststringcacheKey="company:1234567890";
318
+
varresults=await_dailyRepository.GetByIdsAsync([log!.Id], o =>o.QueryLogLevel(LogLevel.Warning).Exclude(e =>e.Date).Include(e =>e.Id).Include("createdUtc").Cache(cacheKey));
Assert.Collection(_cache.Items, c =>Assert.StartsWith("alias:daily-logevents-",c.Key), c =>Assert.Equal($"LogEvent:{cacheKey}",c.Key));
331
+
332
+
// Ensure cache hit by cache key.
333
+
results=await_dailyRepository.GetByIdsAsync([log!.Id], o =>o.QueryLogLevel(LogLevel.Warning).Exclude(e =>e.Date).Include(e =>e.Id).Include("createdUtc").Cache(cacheKey));
0 commit comments