summaryrefslogtreecommitdiff
path: root/vendor/github.com/hashicorp/golang-lru/v2/README.md
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2024-03-04 09:42:11 +0000
committerLibravatar GitHub <noreply@github.com>2024-03-04 09:42:11 +0000
commitadb4cdcf6c9eacd369eaaf5b21774b198d57c040 (patch)
treea4f9c8fe2ce147fa952bcb795690afb9bb2affcb /vendor/github.com/hashicorp/golang-lru/v2/README.md
parent[bugfix] update postgresqlstmt to correctly use postgres err hook (#2711) (diff)
downloadgotosocial-adb4cdcf6c9eacd369eaaf5b21774b198d57c040.tar.xz
[chore]: Bump modernc.org/sqlite from 1.28.0 to 1.29.2 (#2718)
Diffstat (limited to 'vendor/github.com/hashicorp/golang-lru/v2/README.md')
-rw-r--r--vendor/github.com/hashicorp/golang-lru/v2/README.md79
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/golang-lru/v2/README.md b/vendor/github.com/hashicorp/golang-lru/v2/README.md
new file mode 100644
index 000000000..a942eb539
--- /dev/null
+++ b/vendor/github.com/hashicorp/golang-lru/v2/README.md
@@ -0,0 +1,79 @@
+golang-lru
+==========
+
+This provides the `lru` package which implements a fixed-size
+thread safe LRU cache. It is based on the cache in Groupcache.
+
+Documentation
+=============
+
+Full docs are available on [Go Packages](https://pkg.go.dev/github.com/hashicorp/golang-lru/v2)
+
+LRU cache example
+=================
+
+```go
+package main
+
+import (
+ "fmt"
+ "github.com/hashicorp/golang-lru/v2"
+)
+
+func main() {
+ l, _ := lru.New[int, any](128)
+ for i := 0; i < 256; i++ {
+ l.Add(i, nil)
+ }
+ if l.Len() != 128 {
+ panic(fmt.Sprintf("bad len: %v", l.Len()))
+ }
+}
+```
+
+Expirable LRU cache example
+===========================
+
+```go
+package main
+
+import (
+ "fmt"
+ "time"
+
+ "github.com/hashicorp/golang-lru/v2/expirable"
+)
+
+func main() {
+ // make cache with 10ms TTL and 5 max keys
+ cache := expirable.NewLRU[string, string](5, nil, time.Millisecond*10)
+
+
+ // set value under key1.
+ cache.Add("key1", "val1")
+
+ // get value under key1
+ r, ok := cache.Get("key1")
+
+ // check for OK value
+ if ok {
+ fmt.Printf("value before expiration is found: %v, value: %q\n", ok, r)
+ }
+
+ // wait for cache to expire
+ time.Sleep(time.Millisecond * 12)
+
+ // get value under key1 after key expiration
+ r, ok = cache.Get("key1")
+ fmt.Printf("value after expiration is found: %v, value: %q\n", ok, r)
+
+ // set value under key2, would evict old entry because it is already expired.
+ cache.Add("key2", "val2")
+
+ fmt.Printf("Cache len: %d\n", cache.Len())
+ // Output:
+ // value before expiration is found: true, value: "val1"
+ // value after expiration is found: false, value: ""
+ // Cache len: 1
+}
+```