https://github.com/chyroc/filecache
File-based high-performance cache library implemented with go
https://github.com/chyroc/filecache
Last synced: 10 months ago
JSON representation
File-based high-performance cache library implemented with go
- Host: GitHub
- URL: https://github.com/chyroc/filecache
- Owner: chyroc
- License: apache-2.0
- Created: 2019-02-12T16:45:22.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-14T09:22:39.000Z (almost 7 years ago)
- Last Synced: 2025-01-29T08:22:51.996Z (11 months ago)
- Language: Go
- Homepage: https://godoc.org/github.com/Chyroc/filecache
- Size: 29.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# filecache
cache library that store data in local file.
## usage
```go
func Example_Cache() {
cache := filecache.New("./cache.data")
defer os.Remove("./cache.data")
_, err := cache.Get("not-exist")
fmt.Println(err)
fmt.Println(cache.Set("k", "v", time.Minute))
v, err := cache.Get("k")
fmt.Println(v, err)
ttl, err := cache.TTL("k")
fmt.Println(int(math.Ceil(ttl.Seconds())), err)
time.Sleep(time.Second)
ttl, err = cache.TTL("k")
fmt.Println(int(math.Ceil(ttl.Seconds())), err)
fmt.Println(cache.Del("k"))
_, err = cache.Get("k")
fmt.Println(err)
// output:
// not found
//
// v
// 60
// 59
//
// not found
}
```
## benchmark
```
chyroc "github.com/Chyroc/filecache"
dannyBen "github.com/DannyBen/filecache"
fabiorphp "github.com/fabiorphp/cachego"
gadelkareem "github.com/gadelkareem/cachita"
gookit "github.com/gookit/cache"
huntsman "github.com/huntsman-li/go-cache"
miguelmota "github.com/miguelmota/go-filecache"
```
```
pkg: github.com/Chyroc/filecache-benchmark
BenchmarkFileCache/chyroc-8 200 7135164 ns/op
BenchmarkFileCache/huntsman-8 2 537270751 ns/op
BenchmarkFileCache/fabiorphp-8 3 405211720 ns/op
BenchmarkFileCache/dannyBen-8 3 385529791 ns/op
BenchmarkFileCache/gadelkareem-8 3 403604442 ns/op
BenchmarkFileCache/miguelmota-8 1 3222506519 ns/op
```