diff --git a/cache.go b/cache.go index 0f87c92..d81d9a7 100644 --- a/cache.go +++ b/cache.go @@ -136,6 +136,9 @@ func (c *Cache) Replace(key string, value interface{}) bool { // Attempts to get the value from the cache and calles fetch on a miss (missing // or stale item). If fetch returns an error, no value is cached and the error // is returned back to the caller. +// Note that Fetch merely calls the public Get and Set functions. If you want +// a different Fetch behavior, such as thundering herd protection or returning +// expired items, implement it in your application. func (c *Cache) Fetch(key string, duration time.Duration, fetch func() (interface{}, error)) (*Item, error) { item := c.Get(key) if item != nil && !item.Expired() { diff --git a/layeredcache.go b/layeredcache.go index 3ffaf0d..d36d690 100644 --- a/layeredcache.go +++ b/layeredcache.go @@ -131,6 +131,9 @@ func (c *LayeredCache) Replace(primary, secondary string, value interface{}) boo // Attempts to get the value from the cache and calles fetch on a miss. // If fetch returns an error, no value is cached and the error is returned back // to the caller. +// Note that Fetch merely calls the public Get and Set functions. If you want +// a different Fetch behavior, such as thundering herd protection or returning +// expired items, implement it in your application. func (c *LayeredCache) Fetch(primary, secondary string, duration time.Duration, fetch func() (interface{}, error)) (*Item, error) { item := c.Get(primary, secondary) if item != nil { diff --git a/readme.md b/readme.md index 8617f18..b45a487 100644 --- a/readme.md +++ b/readme.md @@ -86,6 +86,8 @@ item, err := cache.Fetch("user:4", time.Minute * 10, func() (interface{}, error) }) ``` +`Fetch` doesn't do anything fancy: it merely uses the public `Get` and `Set` functions. If you want more advanced behavior, such as using a singleflight to protect against thundering herd, support a callback that accepts the key, or returning expired items, you should implement that in your application. + ### Delete `Delete` expects the key to delete. It's ok to call `Delete` on a non-existent key: