Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/knbr13/incache
Simple, fast, concurrent in-memory database.
https://github.com/knbr13/incache
blazingly-fast cache db go golang inmemory-db thread-safe
Last synced: 11 days ago
JSON representation
Simple, fast, concurrent in-memory database.
- Host: GitHub
- URL: https://github.com/knbr13/incache
- Owner: knbr13
- License: mit
- Created: 2023-06-22T00:35:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-22T23:04:20.000Z (7 months ago)
- Last Synced: 2024-05-22T23:28:30.500Z (7 months ago)
- Topics: blazingly-fast, cache, db, go, golang, inmemory-db, thread-safe
- Language: Go
- Homepage:
- Size: 886 KB
- Stars: 14
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## incache
The `incache` package provides a simple cache implementation in Go. It can be used as a package in other Go projects to store key-value pairs in memory. The package is safe to use concurrently with multiple goroutines.
### Installation
To use this package in your Go project, you can install it using `go get`:
```bash
go get github.com/knbr13/incache
```### Example
```go
package mainimport (
"fmt"
"time""github.com/knbr13/incache"
)func main() {
// create a new LRU Cache
c := incache.NewLRU[string, int](10)fmt.Println("keys:", c.Keys())
// set some key-value pairs
c.Set("one", 1)
c.Set("two", 2)
c.Set("three", 3)
c.Set("four", 4)
c.Set("five", 5)c.SetWithTimeout("six", 6, time.Millisecond)
// Get values by key
v, ok := c.Get("one")
if ok {
fmt.Println("Value for key1:", v)
}v, ok = c.Get("two")
if ok {
fmt.Println("Value for key1:", v)
}c.Delete("one")
// create new cache, move data from 'c' to 'c2'
c2 := incache.NewLRU[string, int](10)
c.TransferTo(c2)// create new cache, copy data from 'c2' to 'c3'
c3 := incache.NewLRU[string, int](10)
c2.CopyTo(c3)
}
```### Contributing
Contributions are welcome!
If you find any bugs or have suggestions for improvements, please open an issue or submit a pull request on GitHub.