fluxcd / pkg

Toolkit common packages
https://pkg.go.dev/github.com/fluxcd/pkg
Apache License 2.0
45 stars 84 forks source link

Introduce in-memory caching package #766

Closed souleb closed 1 month ago

souleb commented 2 months ago

This PR will allow caching the authentication credentials retrieved by pkg/oci/auth. It should also enable future usage of the caching underlying mechanism.

Part of: #642

Store design

The store is K/V store that can store arbitrary objects. The store interface is a simplified version of client go store. If an object can be cached there, it should be in our store implementations. This is desirable, because the primary envisioned place for the store usage is during a reconciliation of custom resources retrieved from a shared informer cache.

The keys are generated dynamically with deterministic function. Accepting a function instead of key strings enables user to determine themselves the keys uniqueness constraint.

They store must be thread safe, it should support concurrent programs.

There are 2 main uses cases:

Based on the two scenario above, the store should be optimized for reads.

We also have a scenario that needs keys to expirable and another that need them be evicted based on usage.

Hence two implementations are provided:

errordeveloper commented 2 months ago

Thanks for working on this, @souleb!

The store interface is a simplified version of client go store.

It would be handy to have a link in the code. At the moment this is only mentioned in a commit message and PR description.

What may need to be made more explicit is that the sore is persisted to a file.

souleb commented 2 months ago

Thanks for working on this, @souleb!

The store interface is a simplified version of client go store.

It would be handy to have a link in the code. At the moment this is only mentioned in a commit message and PR description.

What may need to be made more explicit is that the sore is persisted to a file.

There is a comment in store.go pointing to https://pkg.go.dev/k8s.io/client-go/tools/cache#Store.

Persisting to a file will be made in a follow up PR where we will outline the use case we have for it.

errordeveloper commented 1 month ago

Exciting to see this merged! 🌟