Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pkg6/go-cache
Golang Cache package
https://github.com/pkg6/go-cache
Last synced: 7 days ago
JSON representation
Golang Cache package
- Host: GitHub
- URL: https://github.com/pkg6/go-cache
- Owner: pkg6
- License: apache-2.0
- Created: 2023-05-24T09:39:14.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-21T14:49:17.000Z (12 months ago)
- Last Synced: 2024-04-16T00:13:03.646Z (7 months ago)
- Language: Go
- Size: 61.5 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## GoCache
[![Go Report Card](https://goreportcard.com/badge/github.com/pkg6/go-cache)](https://goreportcard.com/report/github.com/pkg6/go-cache)
[![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-blue?logo=go&logoColor=white)](https://pkg.go.dev/github.com/pkg6/go-cache?tab=doc)
[![Sourcegraph](https://sourcegraph.com/github.com/pkg6/go-cache/-/badge.svg)](https://sourcegraph.com/github.com/pkg6/go-cache?badge)
[![Release](https://img.shields.io/github/release/pkg6/go-cache.svg?style=flat-square)](https://github.com/pkg6/go-cache/releases)## Installation
Make sure you have a working Go environment (Go 1.18 or higher is required). See the [install instructions](https://golang.org/doc/install.html).
To install [GoCache](https://github.com/pkg6/go-cache), simply run:
```
go get github.com/pkg6/go-cache
```## Example
```
package mainimport (
"github.com/pkg6/go-cache"
)func main() {
c := cache.New()
c.Extend(cache.NewFileCache())
c.Set("cache", "test", 0)
c.Get("cache")
c.GetMulti([]string{"cache"})
c.Delete("cache")
c.Has("cache")
c.Increment("cache_inc", 1)
c.Decrement("cache_dec", 1)
c.Clear()
c.Pull("cache")
c.Remember("cache", func() any {
return "test1"
}, 0)
}
```