Skip to content

Implement an action cache

Context

The Remote Execution API describes an action cache that maps Action digests to ActionResult messages. It specifies that servers should assume the most recently used results are more likely to be used again (implying an LRU cache), and that servers should ensure any CAS blobs referenced by the ActionResult are still valid before returning it.

BuildGrid does not yet implement this; the relevant API calls currently return UNIMPLEMENTED status codes, and execute requests are immediately rejected unless they have the skip_cache_lookup flag set.

Task Description

While the API design document doesn't specify how the ActionResults should be stored, it seems reasonable to store them in CAS.

  • Implement an LRU cache mapping Action digests to ActionResult digests. (TODO: What backends should we implement? Definitely an in-memory cache, but should we also support an external key-value store of some kind?)
  • Modify ExecutionInstance to store ActionResults in CAS, place their digests in the action cache, and return those cached results for subsequent execute calls.
  • Before returning a cached ActionResult, ensure all of the CAS blobs it references are still valid.
  • Replace ActionCacheService method stubs with working implementations. (TODO: Should we implement UpdateActionResult, which allows clients to bypass the build workers and directly put stuff in the cache? It might make sense to have a flag to enable/disable it.)