-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Cody Littley <[email protected]>
- Loading branch information
1 parent
53fd80d
commit e8ffa50
Showing
17 changed files
with
360 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cache | ||
|
||
// WeightCalculator is a function that calculates the weight of a key-value pair in a Cache. | ||
// By default, the weight of a key-value pair is 1. Cache capacity is always specified in terms of | ||
// the weight of the key-value pairs it can hold, rather than the number of key-value pairs. | ||
type WeightCalculator[K comparable, V any] func(key K, value V) uint64 | ||
|
||
// Cache is an interface for a generic cache. | ||
// | ||
// Unless otherwise noted, Cache implementations are not required to be thread safe. | ||
type Cache[K comparable, V any] interface { | ||
// Get returns the value associated with the key, and a boolean indicating whether the key was found in the cache. | ||
Get(key K) (V, bool) | ||
|
||
// Put adds a key-value pair to the cache. After this operation, values may be dropped if the total weight | ||
// exceeds the configured maximum weight. Will ignore the new value if it exceeds the maximum weight | ||
// of the cache in and of itself. | ||
Put(key K, value V) | ||
|
||
// Size returns the number of key-value pairs in the cache. | ||
Size() int | ||
|
||
// Weight returns the total weight of the key-value pairs in the cache. | ||
Weight() uint64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.