The most likely configuration options to tweak are:
*`MaxItems(int)` - the maximum number of items to store in the cache (default: 5000)
*`GetsPerPromote(int)` - the number of times an item is fetched before we promote it. For large caches with long TTLs, it normally isn't necessary to promote an item after every fetch (default: 3)
*`ItemsToPrune(int)` - the number of items to prune when we hit `MaxItems`. Freeing up more than 1 slot at a time improved performance (default: 500)
Configurations that change the internals of the cache, which aren't as likely to need tweaking:
*`Buckets` - ccache shards its internal map to provide a greater amount of concurrency. The number of buckets is configurable (default: 16)
*`PromoteBuffer(int)` - the size of the buffer to use to queue promotions (default: 1024)
*`DeleteBuffer(int)` the size of the buffer to use to queue deletions (default: 1024)
*`Expired() bool` - whether the item is expired or not
*`TTL() time.Duration` - the duration before the item expires (will be a negative value for expired items)
*`Expires() time.Time` - the time the item will expire
By returning expired items, CCache lets you decide if you want to serve stale content or not. For example, you might decide to serve up slightly stale content (<30secondsold)whilere-fetchingnewerdatainthebackground.Youmightalsodecidetoserveupinfinitelystalecontentifyou'reunabletogetnewdatafromyoursource.
CCache supports a special tracking mode which is meant to be used in conjunction with other pieces of your code that maintains a long-lived reference to data.
In practive, `Release` wouldn't be called until later, at some other place in your code.
There's a couple reason to use the tracking mode if other parts of your code also hold references to objects. First, if you're already going to hold a reference to these objects, there's really no reason not to have them in the cache - the memory is used up anyways.
More important, it helps ensure that you're code returns consistent data. With tracking, "user:4" might be purged, and a subsequent `Fetch` would reload the data. This can result in different versions of "user:4" being returned by different parts of your system.
CCache's `LayeredCache` stores and retrieves values by both a primary and secondary key. Deletion can happen against either the primary and secondary key, or the primary key only (removing all values that share the same primary key).
`LayeredCache` is useful for HTTP caching, when you want to purge all variations of a request. Consider:
`LayeredCache` takes the same configuration object as the main cache, exposes the same optional tracking capabilities, but exposes a slightly different API: