Skip to content

Conversation

@mem
Copy link
Contributor

@mem mem commented Apr 2, 2025

It might be worth offering the option to set a custom cache, possibly with different policies or with a different caching store.

This is almost supported, as cache.Cache is an interface, so it's possible to reimplement it. This is done using a
DefaultKeyRetrieverOption function to pass to NewKeyRetriever that can replace the cache field c. The problem is that the field is not exported, so it's not possible to implement the option outside of the package.

Add that option here. It needs to take into consideration the fact that cache.NewLocalCache ends up starting a goroutine to do clean up tasks. While the goroutine should stop because the cache has been replaced, it's better to not start it in the first place.

@mem mem requested a review from a team as a code owner April 2, 2025 21:24
@mem mem requested review from cinaglia and colin-stuart and removed request for a team April 2, 2025 21:24
@mem mem force-pushed the mem/add-with-cache-opt branch 2 times, most recently from 3d2ffe8 to 8fc6d99 Compare May 16, 2025 23:20
Copy link
Member

@cinaglia cinaglia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mem mem force-pushed the mem/add-with-cache-opt branch from 8fc6d99 to cda1623 Compare May 20, 2025 23:20
It might be worth offering the option to set a custom cache, possibly
with different policies or with a different caching store.

This is almost supported, as cache.Cache is an interface, so it's
possible to reimplement it. This could be done using a
DefaultKeyRetrieverOption function to pass to NewKeyRetriever that can
replace the cache field `c`. The problem is that the field is not
exported, so it's not possible to implement the option outside of the
package, and the type does not offer a function to set the private field
(such a function would make the option unnecessary). The same goes for
the TokenExchangeClient.

Add those options in this change. It needs to take into consideration
the fact that cache.NewLocalCache ends up starting a goroutine to do
clean up tasks. While the goroutine should stop because the cache has
been replaced, it's better to not start it in the first place.

Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
@mem mem force-pushed the mem/add-with-cache-opt branch from cda1623 to 5b452ab Compare June 3, 2025 14:40
@eleijonmarck eleijonmarck merged commit 5455052 into grafana:main Jun 3, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants