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 Concern | Operation Count Multiplier | Default |
---|---|---|
Balanced | 1x | Yes |
Consistent | 6x | No |
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:
- JavaScript
- Go
return await CacheClient.create({
configuration: Configurations.Laptop.v1().withReadConcern(ReadConcern.CONSISTENT),
credentialProvider: CredentialProvider.fromEnvironmentVariable('MOMENTO_API_KEY'),
defaultTtlSeconds: 60,
});
context := context.Background()
credentialProvider, err := auth.NewEnvMomentoTokenProvider("MOMENTO_API_KEY")
if err != nil {
panic(err)
}
defaultTtl := time.Duration(9999)
eagerConnectTimeout := 30 * time.Second
client, err := momento.NewCacheClientWithEagerConnectTimeout(
config.LaptopLatest().WithReadConcern(config.CONSISTENT),
credentialProvider,
defaultTtl,
eagerConnectTimeout,
)
if err != nil {
panic(err)
}
client.Ping(context)