Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
qianbin committed May 15, 2022
1 parent 2be86e6 commit 18c81e0
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A high performance GC-free cache library for Go-lang.

- high performance
- no GC overhead
- LRU-like eviction strategy
- LRU & custom eviction policy
- zero-copy access
- small per-entry space overhead

Expand All @@ -32,13 +32,38 @@ c := directcache.New(0)
key := []byte("DirectCache")
val := []byte("is awesome,")

c.Set([]byte(key), []byte(val))
got, ok := c.Get([]byte(key))
c.Set(key, val)
got, ok := c.Get(key)

fmt.Println(string(key), string(got), ok)
// Output: DirectCache is awesome, true
```

zero-copy access

```go
c.AdvGet(
key,
func(val []byte){
// consume the value
},
true, // peek, which means the recently-used flag won't be added to the accessed entry.
)
```

custom eviction policy
```go
shouldEvict := func(key, val []byte, recentlyUsed bool) bool {
if recentlyUsed {
return false
}
// custom rules...
return true
}

c.SetEvictionPolicy(shouldEvict)
```

## License

The MIT License

0 comments on commit 18c81e0

Please sign in to comment.