Skip to content

Latest commit

 

History

History
46 lines (30 loc) · 1.36 KB

File metadata and controls

46 lines (30 loc) · 1.36 KB

Allegro.CosmosDb.ConsistencyLevelUtilities

This library contains utilities helpful in handling CosmosDb Consistency Levels.

CustomConsistencyLevelReadAttribute

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.\

Example

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 info

More information about overriding database's consistency levels can be found here.