From 74a85afd4b45f7b5f5bdef5e6fc54bae7746fe53 Mon Sep 17 00:00:00 2001 From: motoki317 Date: Fri, 12 Apr 2024 16:53:41 +0900 Subject: [PATCH] Clarify map backend usage --- README.md | 2 +- config.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c2ba6b5..f369440 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ For a more detailed guide, see [reference](https://pkg.go.dev/github.com/motoki3 ## Supported cache backends (cache replacement policy) - Built-in map (default) - - Note: This backend cannot have max number of items configured. It holds all values in memory until expiration. + - Note: This backend cannot have max number of items configured. It holds all values in memory until expiration. For more, see the [documentation](https://pkg.go.dev/github.com/motoki317/sc#WithMapBackend). - LRU (Least Recently Used) - 2Q (Two Queue Cache) diff --git a/config.go b/config.go index 73e7163..61463c5 100644 --- a/config.go +++ b/config.go @@ -37,8 +37,14 @@ func defaultConfig(ttl time.Duration) cacheConfig { } // WithMapBackend specifies to use the built-in map for storing cache items (the default). -// Note that the default map backend will not evict old cache items. If your key's cardinality is high, consider using -// other backends such as LRU. +// +// Note that this default map backend cannot have the maximum number of items configured, +// so it holds all values in memory until expired values are cleaned regularly +// at the interval specified by WithCleanupInterval. +// +// If your key's cardinality is high and if you would like to hard-limit the cache's memory usage, +// consider using other backends such as LRU backend. +// // Initial capacity needs to be non-negative. func WithMapBackend(initialCapacity int) CacheOption { return func(c *cacheConfig) { @@ -138,7 +144,7 @@ func EnableStrictCoalescing() CacheOption { // WithCleanupInterval specifies cleanup interval of expired items. // // Setting interval of 0 (or negative) will disable the cleaner. -// This means if using non-evicting cache backend (that is, the default, built-in map backend), +// This means if you use non-evicting cache backend (that is, the default, built-in map backend), // the cache keeps holding key-value pairs indefinitely. // If cardinality of key is very large, this leads to memory leak. //