Skip to content

Conversation

zhuoyuan-liu
Copy link
Contributor

@zhuoyuan-liu zhuoyuan-liu commented Apr 3, 2025

This PR introduces an in-memory cache to store parameters that rarely change, reducing the number of requests to the backend database. However, it should only be used for bounded values—such as the environment and node key—because the cache is currently unbounded and may grow indefinitely, potentially leading to OOMKilled errors.

At this point, the cache has been added for the environment value only.

@javuto javuto self-assigned this Apr 3, 2025
@javuto javuto added ✨ enhancement New feature or request cache Cache related issues labels Apr 3, 2025
// Environment keeps all TLS Environments
type Environment struct {
// EnvironmentManager keeps all TLS Environments
type EnvironmentManager struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Maybe the name can be EnvManager to reduce its length

@zhuoyuan-liu zhuoyuan-liu marked this pull request as ready for review April 4, 2025 09:42
func NewEnvCache(envs EnvManager) *EnvCache {
// Create a new cache with a 10-minute cleanup interval
envCache := cache.NewMemoryCache(
cache.WithCleanupInterval[TLSEnvironment](2 * time.Hour),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This value is currently hardcoded, and I think we need a more robust approach to configuration management. Otherwise, the number of command-line flags will quickly become unmanageable and difficult to maintain.

Copy link
Collaborator

@javuto javuto left a comment

Choose a reason for hiding this comment

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

Nicely done!

@javuto javuto merged commit 6db6677 into jmpsec:main Apr 6, 2025
25 checks passed
@zhuoyuan-liu zhuoyuan-liu deleted the add-inmemory-cache branch April 14, 2025 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cache Cache related issues ✨ enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants