From a057deaba20530d7f1848e03df6b54d5b63ab970 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Wed, 8 Nov 2023 06:17:14 -0500 Subject: [PATCH] Minor updates * Update the example in the README and small.go example * Version bump in ttlMap.go --- README.md | 4 ++++ example/small/small.go | 3 +++ ttlMap.go | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 78d60d8..605ba35 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,9 @@ func main() { startSize := 3 // initial number of items in map pruneInterval := time.Duration(time.Second * 1) // search for expired items every 'pruneInterval' seconds refreshLastAccessOnGet := true // update item's 'lastAccessTime' on a .Get() + + // any comparable data type such as int, uint64, pointers and struct types (if all field types are comparable) + // can be used as the key type, not just string t := TtlMap.New[string](maxTTL, startSize, pruneInterval, refreshLastAccessOnGet) defer t.Close() @@ -84,6 +87,7 @@ TtlMap length: 0 * Adopted from: [Map with TTL option in Go](https://stackoverflow.com/a/25487392/452281) * * Answer created by: [OneOfOne](https://stackoverflow.com/users/145587/oneofone) * [/u/skeeto](https://old.reddit.com/user/skeeto): suggestions for the `New` function +* `@zhayes` on the Go Discord: helping me with Go Generics ## Disclosure Notification diff --git a/example/small/small.go b/example/small/small.go index 46404af..1456710 100644 --- a/example/small/small.go +++ b/example/small/small.go @@ -12,6 +12,9 @@ func main() { startSize := 3 // initial number of items in map pruneInterval := time.Duration(time.Second * 1) // search for expired items every 'pruneInterval' seconds refreshLastAccessOnGet := true // update item's 'lastAccessTime' on a .Get() + + // any comparable data type such as int, uint64, pointers and struct types (if all field types are comparable) + // can be used as the key type, not just string t := TtlMap.New[string](maxTTL, startSize, pruneInterval, refreshLastAccessOnGet) defer t.Close() diff --git a/ttlMap.go b/ttlMap.go index 8b3fe60..38cb585 100644 --- a/ttlMap.go +++ b/ttlMap.go @@ -22,7 +22,7 @@ import ( "time" ) -const version string = "1.4.0" +const version string = "1.5.0" type CustomKeyType interface { comparable