Ejemplo n.º 1
0
            private async ValueTask <ProjectionTargetMetadataCacheEntry> GetMetadataAsync(ProjectionTargetDescriptor <TProjectionId> target,
                                                                                          CancellationToken cancellation)
            {
                if (!_targetMetadataCache.TryGetValue(target, out var entry))
                {
                    var entryId  = ProjectionTargetMetadata.GenerateId(target.TargetId.ToString(), target.TargetType.GetUnqualifiedTypeName());
                    var metadata = await _database.GetAsync <ProjectionTargetMetadata>(p => p.Id == entryId, cancellation).FirstOrDefault();

                    var originalMetadata = metadata;
                    var touched          = false;

                    if (metadata == null)
                    {
                        metadata = new ProjectionTargetMetadata
                        {
                            TargetId   = target.TargetId,
                            TargetType = target.TargetType.GetUnqualifiedTypeName()
                        };

                        touched = true;
                    }

                    entry = new ProjectionTargetMetadataCacheEntry(originalMetadata, metadata, touched);
                    _targetMetadataCache.Add(target, entry);
                }

                return(entry);
            }
Ejemplo n.º 2
0
            private async ValueTask <ProjectionTargetMetadataCacheEntry> GetMetadataAsync(ProjectionTargetDescriptor target,
                                                                                          CancellationToken cancellation)
            {
                if (!_targetMetadataCache.TryGetValue(target, out var entry))
                {
                    var entryId  = ProjectionTargetMetadata.GenerateId(target.TargetId, target.TargetType.GetUnqualifiedTypeName());
                    var metadata = await _database.GetAsync <ProjectionTargetMetadata>(p => p.Id == entryId, cancellation).FirstOrDefault();

                    entry = new ProjectionTargetMetadataCacheEntry(metadata, metadata, touched: false);

                    if (metadata != null)
                    {
                        _targetMetadataCache.Add(target, entry);
                    }
                }

                return(entry);
            }