By default, the client cache is strictly coherent: the Scaleout.Client library always performs a version check with the ScaleOut service before returning an object to a caller. If strict coherency is not needed, performance can be improved by reducing the frequency of version checks.
Do not increase a cache's coherency interval unless you are certain that stale reads are acceptable to your application's business requirements.
Setting the Coherency Interval
A cache's coherency interval is a TimeSpan that specifies the maximum amount of time that can elapse before the client library performs a round-trip to the authoritative ScaleOut service. During this interval, a requested object can be returned directly from the in-process cache if its age falls within the specified TimeSpan.
A locking read operation such as Cache.ReadExclusive will always perform a round trip to the ScaleOut service to coordinate distributed locks and will ignore any coherency interval settings.
By default, a cache's coherency interval is set to zero, causing it to check with the service on every call. Increasing this interval above zero will improve performance by reducing the frequency of version checks but will also increase the likelihood that a read call will return stale data.
There are two ways to increase the coherency interval for read operations:
- On a cache-wide basis, increase the
coherencyIntervalvalue in your config file or programmatically using CacheBuilder.SetCoherencyInterval.
- For individual reads, supply a ReadOptions struct to the call, setting ClientCacheUsage to OverrideCoherencyInterval and the CoherencyInterval property to the desired duration.
Coherency and the Network Cache
The in-process network cache also honors the cache-wide coherency interval setting, making it possible to retrieve a deep copy of an object without making a round trip to the ScaleOut service.
For an individual read call, it is possible to override the cache's coherency interval when reading a deep copy: supply a ReadOptions struct to the call, setting ClientCacheUsage to OverrideCoherencyIntervalDeepCopy and the CoherencyInterval property to the desired duration.