buildgrid.server.actioncache.caches.lru_cache module

class buildgrid.server.actioncache.caches.lru_cache.LruActionCache(storage: StorageABC, max_cached_refs: int, allow_updates: bool = True, cache_failed_actions: bool = True)

Bases: ActionCacheABC

In-memory Action Cache implementation with LRU eviction.

This cache has a configurable fixed size, evicting the least recently accessed entry when adding a new entry would exceed the fixed size. The cache is entirely stored in memory so its contents are lost on restart.

This type of cache is ideal for use cases that need a simple and fast cache, with no requirements for longevity of the cache content. It is not recommended to use this type of cache in situations where you may wish to obtain cached results a reasonable time in the future, due to its fixed size.

get_action_result(action_digest: Digest) ActionResult

Retrieves the cached result for an Action.

If there is no cached result found, returns None.

Parameters:

action_digest (Digest) – The digest of the Action to retrieve the cached result of.

update_action_result(action_digest: Digest, action_result: ActionResult) None

Stores a result for an Action in the cache.

If the result has a non-zero exit code and cache_failed_actions is False for this cache, the result is not cached.

Parameters:
  • action_digest (Digest) – The digest of the Action whose result is being cached.

  • action_result (ActionResult) – The result to cache for the given Action digest.