This library contains utilities helpful in handling CosmosDb Consistency Levels.
CosmosDb database has always some consistency level set (by default it's the Session Level - see more details
here). This attribute should be used alongside
ContainerExtensions.ReadItemWithCustomConsistencyAsync
method to mark entities that can use a relaxed consistency
settings to optimize RU cost or read latency.
To prevent cold start issues, please invoke ContainerExtensions.WarmUp()
method in your program's entrypoint.\
Usage example can be found in the Allegro.CosmosDb.Demo
project.
Entity definition:
[CustomConsistencyLevelRead(ConsistencyLevel.Eventual)]
public class CosmosDocument
{
// some properties
}
Reading the entity with lowered consistency:
using Allegro.CosmosDb.ConsistencyLevelUtilities;
// ...
var item = await container.ReadItemWithCustomConsistencyAsync<CosmosDocument>(
documentId,
new PartitionKey(documentId),
cancellationToken: HttpContext.RequestAborted);
}
More information about overriding database's consistency levels can be found here.