Skip to content

Commit 74a85af

Browse files
committed
Clarify map backend usage
1 parent fd1c572 commit 74a85af

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ For a more detailed guide, see [reference](https://pkg.go.dev/github.com/motoki3
5353
## Supported cache backends (cache replacement policy)
5454

5555
- Built-in map (default)
56-
- Note: This backend cannot have max number of items configured. It holds all values in memory until expiration.
56+
- 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).
5757
- LRU (Least Recently Used)
5858
- 2Q (Two Queue Cache)
5959

config.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ func defaultConfig(ttl time.Duration) cacheConfig {
3737
}
3838

3939
// WithMapBackend specifies to use the built-in map for storing cache items (the default).
40-
// Note that the default map backend will not evict old cache items. If your key's cardinality is high, consider using
41-
// other backends such as LRU.
40+
//
41+
// Note that this default map backend cannot have the maximum number of items configured,
42+
// so it holds all values in memory until expired values are cleaned regularly
43+
// at the interval specified by WithCleanupInterval.
44+
//
45+
// If your key's cardinality is high and if you would like to hard-limit the cache's memory usage,
46+
// consider using other backends such as LRU backend.
47+
//
4248
// Initial capacity needs to be non-negative.
4349
func WithMapBackend(initialCapacity int) CacheOption {
4450
return func(c *cacheConfig) {
@@ -138,7 +144,7 @@ func EnableStrictCoalescing() CacheOption {
138144
// WithCleanupInterval specifies cleanup interval of expired items.
139145
//
140146
// Setting interval of 0 (or negative) will disable the cleaner.
141-
// This means if using non-evicting cache backend (that is, the default, built-in map backend),
147+
// This means if you use non-evicting cache backend (that is, the default, built-in map backend),
142148
// the cache keeps holding key-value pairs indefinitely.
143149
// If cardinality of key is very large, this leads to memory leak.
144150
//

0 commit comments

Comments
 (0)