Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In-Memory Cache for CF Resources #59

Open
wants to merge 64 commits into
base: main
Choose a base branch
from
Open

Conversation

santiago-ventura
Copy link
Contributor

Summary

We want to introduce a mechanism for batching and caching CF resources. By storing the CF resources in memory, we aim to reduce the number of requests to the CF API and avoid reaching the rate limit.

Approach

  • The cache feature is optional and can be enabled via the environment variable RESOURCE_CACHE_ENABLED, which can have values of true or false.

  • Another environment variable, CACHE_TIMEOUT, is introduced to control the refresh of the cached resources, based on a lastCacheTime attribute of the Cache instance.

  • At the start of the operator, an instance of a Config object is created. This config object has two attributes with values of the environment variables described above.

  • The first time the' spaceClient' is created, an instance of the Cache object is created and populated.

  • The Cache instance will be refreshed every time the cache time-out is reached.

  • This PR has been tested manually in one of our Kubernetes Clusters.
  • A second PR will be following this one; implementing the solution for the CF resources Space, and ServiceBinding. A third PR will have the documentation and the integration, and unit test.

internal/cf/instance.go Outdated Show resolved Hide resolved
@@ -210,5 +254,257 @@ func NewSpaceHealthChecker(spaceGuid string, url string, username string, passwo
}
}

if config.IsResourceCacheEnabled && client.resourceCache == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TheBigElmo
It assigns the resourceCache created by the organization unit client and space client and will use the spaceCache populated by the organization unit client in the cf/health.go.

Currently the health.go uses the spaceClient to call the CF API. Is this OK to use the cache populated by the organization client?

@RalfHammer RalfHammer changed the title In-Memory Cache for CF Resources (Service Instances) In-Memory Cache for CF Resources Oct 7, 2024
RalfHammer
RalfHammer previously approved these changes Oct 7, 2024
@RalfHammer RalfHammer self-assigned this Oct 9, 2024
@RalfHammer RalfHammer requested review from RalfHammer and removed request for RalfHammer October 9, 2024 12:50
@RalfHammer RalfHammer mentioned this pull request Oct 10, 2024
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