private async Task <ReadStreamPage> FilterExpired( ReadStreamPage page, ReadNextStreamPage readNext, CancellationToken cancellationToken) { if (page.StreamId.StartsWith("$")) { return(page); } int?maxAge = _metadataMaxAgeCache == null ? null : await _metadataMaxAgeCache.GetMaxAge(page.StreamId, cancellationToken); if (!maxAge.HasValue) { return(page); } var currentUtc = GetUtcNow(); var valid = new List <StreamMessage>(); foreach (var message in page.Messages) { if (message.CreatedUtc.AddSeconds(maxAge.Value) > currentUtc) { valid.Add(message); } else { PurgeExpiredMessage(message); } } return(new ReadStreamPage( page.StreamId, page.Status, page.FromStreamVersion, page.NextStreamVersion, page.LastStreamVersion, page.LastStreamPosition, page.ReadDirection, page.IsEnd, readNext, valid.ToArray())); }
public async Task When_lookup_for_uncached_stream_with_then_should_not_hit_cache() { string streamId = "stream"; await _store.SetStreamMetadata(streamId, ExpectedVersion.Any, 60); var maxAge = await _cache.GetMaxAge(streamId); maxAge.Value.ShouldBe(60); _cache.Count.ShouldBe(1); _cache.CacheHitCount.ShouldBe(0); }