Documentation ¶
Overview ¶
Package unarycache allows you to cache responses for unary gRPC messages.
Some gRPC unary message take a considerable amount of compute to build the response. This package will allow users to cache this response.
For the time being it is implemented using a simple in-memory least-recently-used cache.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[Key comparable, Value any] struct { // contains filtered or unexported fields }
Cache is a cache that stores values that can be uniquely computed for a specific key.
func New ¶
func New[Key comparable, Value any](maxEntries int, generator Generator[Key, Value]) (*Cache[Key, Value], error)
New creates a new Cache. The cache will hold at maximum `maxEntries`, if more than this many entries are added then the least-recently-used one will be evicted from the cache. If a repository-scoped key does not exist in the cache, then the generator function will be called to compute the value for the given repository and key.
type Generator ¶
type Generator[Key comparable, Value any] func(context.Context, *localrepo.Repo, Key) (Value, error)
Generator is a function that computes a cacheable value for a repository based on the given key. The key must uniquely identify the result. A valid choice would for example be an object ID.