https://github.com/gitbookio/diskache
Lightweight Golang disk cache
https://github.com/gitbookio/diskache
Last synced: 5 months ago
JSON representation
Lightweight Golang disk cache
- Host: GitHub
- URL: https://github.com/gitbookio/diskache
- Owner: GitbookIO
- Created: 2015-12-16T14:37:36.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-10-28T14:49:15.000Z (about 9 years ago)
- Last Synced: 2025-04-04T05:11:09.652Z (9 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 13
- Watchers: 4
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# diskache
Lightweight Golang disk cache.
## Get
```Shell
$ go get github.com/GitbookIO/diskache
```
## Use
```Go
import (
"fmt"
"github.com/GitbookIO/diskache"
)
// Create an instance
opts := diskache.Opts{
Directory: "diskache_place",
}
dc := diskache.New(opts)
// Add data to cache
spelling := []byte{'g', 'o', 'l', 'a', 'n', 'g'}
err := dc.Set("spelling", spelling)
if err != nil {
fmt.Println("Impossible to set data in cache")
}
// Read from cache
cached, inCache := dc.Get("spelling")
if inCache {
fmt.Println(string(cached))
}
// Read stats
stats := dc.Stats()
reflect.DeepEqual(stats, Stats{
Directory: "diskache_place",
Items: 1,
})
// Cleanup
err = dc.Clean()
if err != nil {
fmt.Println("Impossible to clean cache")
}
```