-
Notifications
You must be signed in to change notification settings - Fork 178
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
How do I write a package that I can adjust the #20
Comments
Just wrap fastcache.Cache into your struct. Something like the following: import "github.com/VictoriaMetrics/fastcache"
type Cache struct {
c *fastcache.Cache
}
func New(maxBytes int) *Cache {
return &Cache{
c: fastcache.New(maxBytes),
}
}
func (c *Cache) Set(k,v []byte) {
// do something before fastcache.Set
// Call fastcache.Set
c.c.Set(k, v)
} |
Thanks! |
I have multiple packages trying to use this
How do I share this same cache from multiple other packages? |
Just initialize cache and store it inside package mycustomized_cache
var cache = New(123456789)
// Set must be called from another packages
func Set(k, v []byte) {
cache.Set(k, v)
} |
Can I initialize the cache , var cache = mycustomized_cache.New(123456789) from
first? then use it in other packages? |
Yes, but in this case you should manually pass the initialized cache to all the packages that use it. |
oic. I get it thanks. |
Basically I would like to make my pre-processing of fastcache to be done so I can assign the size of the cache inside my program instead of directly on fastcache.
How do I do this?
The text was updated successfully, but these errors were encountered: