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

There is no way to close a Ristretto cache. #274

Open
OhJuhun opened this issue Feb 19, 2025 · 0 comments
Open

There is no way to close a Ristretto cache. #274

OhJuhun opened this issue Feb 19, 2025 · 0 comments

Comments

@OhJuhun
Copy link

OhJuhun commented Feb 19, 2025

Hello,

I am using gocache and finding it very useful. However, I have encountered an issue.

I am using Ristretto alongside gocache, and Ristretto internally spawns goroutines. These goroutines can be terminated using the Close() method provided by Ristretto. Unfortunately, in the current implementation of gocache, there is no way to terminate these goroutines. While Clear(ctx context.Context) is available, in the case of Ristretto, it only clears the cache and starts a new goroutine instead of terminating the existing one.

As a result, when the application undergoes a hot reload, even after calling Clear, the existing goroutines remain active. It seems there is no way to address this issue at the moment. Is there any possibility for this to be changed or improved in the future?

If the cache is created and returned as in the code below, the calling function will not be able to close the Ristretto cache.
example:

func createCache() (*Cache[T], error) {
	ristrettoCache, err := ristretto.NewCache(&ristretto.Config{
		NumCounters: 100,
		MaxCost:     1 << 30,
		BufferItems: 64,
	})
	if err != nil {
		return nil, err
	}
	cacheStore := ristrettostore.NewRistretto(ristrettoCache)
	myCache := cache.New[string](cacheStore)

	return myCache, nil
}

Thank you!

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

No branches or pull requests

1 participant