Are range reads cached in the C client?

I was wondering if FDB caches range reads in the C client?

For example, suppose in my layer code, I do a range read to get all key values that have a prefix of ("some", "subspace",).

After this future resolves and all values have been collected by the layer code, if I were to issue another range read for prefix ("some", "subspace", "inner", "data") within the same transaction, would the second request still hit the storage server or will the C client return a cached result, saving itself a trip to the storage server?

Yes, by default, the FDB C client does maintain a cache of read ranges, and it will use that if possible to save trips to the storage server.

That cache is managed as a part of the “read your writes” code (see: ReadYourWrites.actor.h and ReadYourWrites.actor.cpp). The primary goal of that code is to maintain a set of updates performed by your client so that if you read a key that your client has already written in the same transaction, you get back the new value (that is, the one you just wrote) instead of a previous value. However, that cache also contains ranges you’ve already read (even if there are no modifications) which similarly will be used purely to avoid duplicate lookups.

Note that if you disable ReadYourWrites (via the transaction option: set_read_your_writes_disable), then this will disable both the write cache (so you will no longer read your own writes, as you might expect) and the read cache (so you will now re-issue reads for previously read ranges). So that’s something to be aware of, performance-wise, if you end up needing that option.

3 Likes