Skip to content

Conversation

kimpenhaus
Copy link
Contributor

@kimpenhaus kimpenhaus commented Jul 7, 2025

This pull request introduces FusionCache to manage the caching of resource generations. This change replaces the simple, volatile in-memory cache with a more powerful and flexible two-level caching system.

Motivation:
The previous implementation used a simple in-memory cache, which had a significant drawback: it was volatile. Upon a pod restart, the entire cache was lost, forcing the operator to perform a full reconciliation of observed resources he retrieves events for. This is inefficient and can put a significant load on the Kubernetes API server.

By integrating FusionCache, we can address these issues:

  1. Flexibility: It provides seamless support for a two-level (L1/L2) caching strategy. Developers can continue to use a fast in-memory (L1) cache by default, requiring no extra configuration.

  2. Scalability & Resilience: For production and HA setups, a distributed (L2) cache (e.g., Redis) can be easily configured. This ensures that the cache state is persistent across restarts and shared between multiple operator instances, preventing unnecessary reconciliation cycles.

  3. Configurability: A new configuration delegate, , is introduced in the OperatorSettings. This allows users to easily customize the caching behavior to fit their specific needs, such as adding a serializer, configuring a distributed cache, or adjusting entry options. ConfigureResourceWatcherEntityCache

This change makes the operator more robust, performant, and suitable for demanding production environments while maintaining the simplicity of the default configuration.

Furthermore, this can lay the groundwork for leveraging FusionCache to persist enqueued reconciliation requests in the future, ensuring that they are not lost during pod restarts.

…g (hybrid cache)

- Integrated FusionCache for robust caching in resource watchers.
- Enhanced default configuration with extensible settings in `OperatorSettings`.
- Improved concurrency handling using `SemaphoreSlim` for entity events.
- Updated tests and dependencies to reflect caching changes.
…nt entity locks

- Renamed `DefaultCacheConfiguration` to `DefaultResourceWatcherCacheConfiguration` for clarity.
- Introduced cache key prefix to improve cache segmentation.
- Removed `ConcurrentDictionary` for entity locks to simplify concurrency management.
- Refactored event handling logic for "added" and "modified" events to streamline codebase.
- Updated `ConfigureResourceWatcherEntityCache` to use `IFusionCacheBuilder` for extensibility.
- Moved resource watcher cache setup logic to `WithResourceWatcherCaching` extension.
- Added detailed XML comments for `EntityLoggingScope` to improve documentation.
- Removed redundant `DefaultResourceWatcherCacheConfiguration`.
- Renamed `WithResourceWatcherCaching` to `WithResourceWatcherEntityCaching` for clarity.
- Updated `CacheExtensions` to be `internal` to limit scope.
- Removed unused dependency on `ZiggyCreatures.Caching.Fusion`.
- Added a new `Caching` documentation page explaining resource watcher caching with FusionCache and configuration options (in-memory and distributed).
- Updated sidebar positions for `Deployment`, `Utilities`, and `Testing` to accommodate the new `Caching` page.
…usionCache details

- Improved explanations for in-memory and distributed caching setups.
- Added example code for customizing resource watcher cache with FusionCache.
- Included references to FusionCache and Redis documentation for further guidance.
@buehler
Copy link
Collaborator

buehler commented Jul 15, 2025

Amazing, thank you for this!
I will review/merge this as soon as possible. Currently the repository is in transition phase. The work has been accepted by the .net-foundation, and as such, will be transferred to their main organization.

After this has been done, I'll happily look at the change.

Thanks for the contribution!

@kimpenhaus
Copy link
Contributor Author

That's amazing news - congrats for this! ☺️

@buehler buehler merged commit 2681965 into dotnet:main Jul 16, 2025
4 checks passed
@kimpenhaus
Copy link
Contributor Author

Thanks Christoph / @buehler 🙏

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.

2 participants