Skip to main content

What is Read Concern?

By default, a Momento Cache follows an eventual consistency model. That is, if you write a value from the cache, and then quickly read it back within a small fraction of a second, there is a slim, but possible chance that the response will not reflect the most recently updated value. Momento clients provide a configuration option ReadConcern, which can be used to tune this behavior. The ReadConcern configuration can be modified to tune the level of consistency and responsiveness that your system requires. It can be modified accordingly:

Read ConcernOperation Count MultiplierDefault
Balanced1xYes
Consistent6xNo
note

Since this configuration is specified at the client level, it will be used for all api calls from that client. If there are only a few api calls that require read consistency, it is best to create 2 separate clients, one for a Consistent ReadConcern, and another for a Balanced ReadConcern. This way, only the consistent read requests will incur the 6x operations count multiplier.

An example of instantiating a new client with a Consistent ReadConcern is shown below:

return await CacheClient.create({
configuration: Configurations.Laptop.v1().withReadConcern(ReadConcern.CONSISTENT),
credentialProvider: CredentialProvider.fromEnvironmentVariable('MOMENTO_API_KEY'),
defaultTtlSeconds: 60,
});
info
Full example code and imports can be found here