-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
71 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,42 @@ | ||
# evcache | ||
|
||
[![Go Reference](https://pkg.go.dev/badge/github.com/mgnsk/evcache/v3.svg)](https://pkg.go.dev/github.com/mgnsk/evcache/v3) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/mgnsk/evcache/v3)](https://goreportcard.com/report/github.com/mgnsk/evcache/v3) | ||
[![Go Reference](https://pkg.go.dev/badge/github.com/mgnsk/evcache/v4.svg)](https://pkg.go.dev/github.com/mgnsk/evcache/v4) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/mgnsk/evcache/v4)](https://goreportcard.com/report/github.com/mgnsk/evcache/v4) | ||
|
||
Package evcache implements a concurrent key-value cache with capacity overflow eviction, item expiry and deduplication. | ||
|
||
`import "github.com/mgnsk/evcache/v3"` | ||
|
||
Package evcache implements a concurrent key-value cache with capacity overflow eviction, item expiry and deduplication. | ||
`import "github.com/mgnsk/evcache/v4"` | ||
|
||
### Example | ||
|
||
```go | ||
c := evcache.New[string, string](10) | ||
|
||
// Fetches an existing value or calls the callback to get a new value. | ||
result, err := c.Fetch("key", time.Minute, func() (string, error) { | ||
// Possibly a very long network call. It only blocks write access to this key. | ||
// Read access to the key is always non-blocking. | ||
return "value", nil | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/mgnsk/evcache/v4" | ||
) | ||
|
||
func main() { | ||
c := evcache.New[string, string]( | ||
evcache.WithCapacity(128), | ||
evcache.WithPolicy(evcache.LRU), | ||
evcache.WithTTL(time.Minute), | ||
) | ||
|
||
// Fetches an existing value or calls the callback to get a new value. | ||
result, err := c.Fetch("key", func() (string, error) { | ||
// Possibly a very long network call. It only blocks write access to this key. | ||
// Read access for this key returns as if the value does not exist. | ||
return "value", nil | ||
}) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Use the result. | ||
println(result) | ||
} | ||
|
||
// Use the result. | ||
_ = result | ||
``` |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
Package evcache implements a key-value cache with capacity overflow eviction, item expiry and deduplication. | ||
Package evcache implements a concurrent key-value cache with capacity overflow eviction, item expiry and deduplication. | ||
*/ | ||
package evcache |
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,29 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/mgnsk/evcache/v4" | ||
) | ||
|
||
func main() { | ||
c := evcache.New[string, string]( | ||
evcache.WithCapacity(128), | ||
evcache.WithPolicy(evcache.LRU), | ||
evcache.WithTTL(time.Minute), | ||
) | ||
|
||
// Fetches an existing value or calls the callback to get a new value. | ||
result, err := c.Fetch("key", func() (string, error) { | ||
// Possibly a very long network call. It only blocks write access to this key. | ||
// Read access for this key returns as if the value does not exist. | ||
return "value", nil | ||
}) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Use the result. | ||
println(result) | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module github.com/mgnsk/evcache/v3 | ||
module github.com/mgnsk/evcache/v4 | ||
|
||
go 1.22 | ||
|
||
|
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