-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add in-memory caching pkg #1189
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
// Contents returns all key-value pairs in the cache encodes as a string. | ||
func (c *Cache) Contents() string { | ||
items := c.c.Items() | ||
res := make([]string, 0, len(items)) | ||
for k := range items { | ||
res = append(res, k) | ||
} | ||
return strings.Join(res, ",") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion (optional): If you do want to add convenience methods for actually serializing/deserializing the data, we could use strings.Replacer to escape commas (assuming it has an acceptable benchmark).
For example:
func unescape(s string) string {
replacer := strings.NewReplacer(`\,`, ",")
return replacer.Replace(s)
}
func escape(s string) string {
replacer := strings.NewReplacer(",", `\,`)
return replacer.Replace(s)
}
caching library used -> https://pkg.go.dev/github.com/patrickmn/go-cache?utm_source=godoc