public async Task <ISnapshot> GetSnapshot <T>(string bucket, Id streamId, Id[] parents) where T : IEntity { var streamName = _streamGen(_registrar.GetVersionedName(typeof(T)), StreamTypes.Snapshot, bucket, streamId, parents); Logger.DebugEvent("Get", "[{Stream:l}]", streamName); if (_snapshots != null) { var snapshot = await _snapshots.Retrieve(streamName).ConfigureAwait(false); if (snapshot != null) { _metrics.Mark("Snapshot Cache Hits", Unit.Items); Logger.DebugEvent("Cached", "[{Stream:l}] version {Version}", streamName, snapshot.Version); return(snapshot); } } _metrics.Mark("Snapshot Cache Misses", Unit.Items); // Check store directly (this might be a new instance which hasn't caught up to snapshot stream yet var read = await _store.GetEventsBackwards(streamName, StreamPosition.End, 1).ConfigureAwait(false); if (read != null && read.Any()) { var @event = read.Single(); var snapshot = new Snapshot { EntityType = @event.Descriptor.EntityType, Bucket = bucket, StreamId = streamId, Timestamp = @event.Descriptor.Timestamp, Version = @event.Descriptor.Version, Payload = @event.Event as IState }; Logger.DebugEvent("Read", "[{Stream:l}] version {Version}", streamName, snapshot.Version); return(snapshot); } Logger.DebugEvent("NotFound", "[{Stream:l}]", streamName); return(null); }