Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/faabiosr/cachego
Golang Cache component - Multiple drivers
https://github.com/faabiosr/cachego
boltdb cache chain driver file map memcached mongodb redis sqlite syncmap
Last synced: 20 days ago
JSON representation
Golang Cache component - Multiple drivers
- Host: GitHub
- URL: https://github.com/faabiosr/cachego
- Owner: faabiosr
- License: mit
- Created: 2016-10-05T18:10:03.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-03T13:31:00.000Z (9 months ago)
- Last Synced: 2024-04-14T12:12:58.718Z (8 months ago)
- Topics: boltdb, cache, chain, driver, file, map, memcached, mongodb, redis, sqlite, syncmap
- Language: Go
- Size: 150 KB
- Stars: 349
- Watchers: 9
- Forks: 24
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - cachego - Golang Cache component for multiple drivers. (Database / Caches)
- go-awesome - cachego - supports Redis, Bolt and other cache interfaces (Open source library / Cache)
- awesome-go-extra - cachego - Multiple drivers|180|11|0|2016-10-05T18:10:03Z|2022-06-10T16:30:19Z| (Generators / Caches)
README
# Cachego
[![Codecov branch](https://img.shields.io/codecov/c/github/faabiosr/cachego/master.svg?style=flat-square)](https://codecov.io/gh/faabiosr/cachego)
[![GoDoc](https://img.shields.io/badge/godoc-reference-5272B4.svg?style=flat-square)](https://pkg.go.dev/github.com/faabiosr/cachego)
[![Go Report Card](https://goreportcard.com/badge/github.com/faabiosr/cachego?style=flat-square)](https://goreportcard.com/report/github.com/faabiosr/cachego)
[![License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](https://github.com/faabiosr/cachego/blob/master/LICENSE)Simple interface for caching
## Installation
Cachego requires Go 1.18 or later.
```
go get github.com/faabiosr/cachego
```## Usage
```go
package mainimport (
"log"
"time""github.com/faabiosr/cachego/sync"
)func main() {
cache := sync.New()if err := cache.Save("user_id", "1", 10*time.Second); err != nil {
log.Fatal(err)
}id, err := cache.Fetch("user_id")
if err != nil {
log.Fatal(err)
}log.Printf("user id: %s \n", id)
keys := cache.FetchMulti([]string{"user_id", "user_name"})
for k, v := range keys {
log.Printf("%s: %s\n", k, v)
}if cache.Contains("user_name") {
cache.Delete("user_name")
}if _, err := cache.Fetch("user_name"); err != nil {
log.Printf("%v\n", err)
}if err := cache.Flush(); err != nil {
log.Fatal(err)
}
}```
## Supported drivers
- [Bolt](/bolt)
- [Chain](/chain)
- [File](/file)
- [Memcached](/memcached)
- [Mongo](/mongo)
- [Redis](/redis)
- [Sqlite3](/sqlite3)
- [Sync](/sync)## Documentation
Read the full documentation at [https://pkg.go.dev/github.com/faabiosr/cachego](https://pkg.go.dev/github.com/faabiosr/cachego).
## Development
### Requirements
- Install [docker](https://docs.docker.com/install/)
- Install [docker-compose](https://docs.docker.com/compose/install/)### Makefile
```sh
// Clean up
$ make clean//Run tests and generates html coverage file
$ make cover// Up the docker containers for testing
$ make docker// Format all go files
$ make fmt//Run linters
$ make lint// Run tests
$ make test
```## License
This project is released under the MIT licence. See [LICENSE](https://github.com/faabiosr/cachego/blob/master/LICENSE) for more details.