Skip to content

Commit

Permalink
tweak readme
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Jan 2, 2024
1 parent f70f475 commit 03bebba
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

* Simple
- No Dependency
- Less 500 lines of Go(excluding tests)
- Less 1000 lines of Go
* Fast
- Faster than all well-known **LRU** caches
- Zero memory allocs
Expand All @@ -15,10 +15,11 @@
- Continuous memory layout
* Memory efficient
- Uses only 24 extra bytes per cache object
- TTL (8 bytes) + ArrayList node (2 x 4 bytes) + Key hash (4 bytes) + Hash Entry index (4 bytes)

### Getting Started

try on https://go.dev/play/p/XhMxFJe8jcy
try on https://go.dev/play/p/CDWiToYEvWQ
```go
package main

Expand All @@ -29,15 +30,20 @@ import (
)

func main() {
c := lru.New[string, int](1024)
c := lru.NewWithLoader[string, int](1024, func(string) (int, time.Duration, error) {
return 42, time.Hour, nil
})

c.SetWithTTL("a", 1, 1000*time.Millisecond)
c.SetWithTTL("a", 1, 200*time.Millisecond)
println(c.Get("a"))

time.Sleep(500 * time.Millisecond)
time.Sleep(100 * time.Millisecond)
println(c.Get("a"))

time.Sleep(1500 * time.Millisecond)
time.Sleep(150 * time.Millisecond)
println(c.Get("a"))

println(c.GetOrLoad("a", nil))
println(c.Get("a"))
}
```
Expand All @@ -50,19 +56,19 @@ goos: linux
goarch: amd64
cpu: AMD EPYC 7763 64-Core Processor
BenchmarkCloudflareGet
BenchmarkCloudflareGet-8 32122790 183.9 ns/op 18 B/op 1 allocs/op
BenchmarkCloudflareGet-8 34575751 171.1 ns/op 17 B/op 1 allocs/op
BenchmarkEcacheGet
BenchmarkEcacheGet-8 49922084 120.0 ns/op 5 B/op 0 allocs/op
BenchmarkEcacheGet-8 52730455 114.2 ns/op 5 B/op 0 allocs/op
BenchmarkRistrettoGet
BenchmarkRistrettoGet-8 33818906 195.6 ns/op 41 B/op 1 allocs/op
BenchmarkRistrettoGet-8 34192080 172.0 ns/op 41 B/op 1 allocs/op
BenchmarkTheineGet
BenchmarkTheineGet-8 29022984 208.9 ns/op 0 B/op 0 allocs/op
BenchmarkTheineGet-8 29694378 202.5 ns/op 0 B/op 0 allocs/op
BenchmarkOtterGet
BenchmarkOtterGet-8 71440144 85.35 ns/op 0 B/op 0 allocs/op
BenchmarkOtterGet-8 76333077 74.27 ns/op 0 B/op 0 allocs/op
BenchmarkPhusluGet
BenchmarkPhusluGet-8 60555633 98.51 ns/op 0 B/op 0 allocs/op
BenchmarkPhusluGet-8 73868793 82.88 ns/op 0 B/op 0 allocs/op
PASS
ok command-line-arguments 61.404s
ok command-line-arguments 46.827s
```

[godoc-img]: http://img.shields.io/badge/godoc-reference-blue.svg
Expand Down

0 comments on commit 03bebba

Please sign in to comment.