Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/morkid/gocache-elasticsearch
simple elasticsearch cache adapter for golang
https://github.com/morkid/gocache-elasticsearch
Last synced: about 1 month ago
JSON representation
simple elasticsearch cache adapter for golang
- Host: GitHub
- URL: https://github.com/morkid/gocache-elasticsearch
- Owner: morkid
- License: mit
- Created: 2021-03-09T00:39:50.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-09T13:16:22.000Z (almost 4 years ago)
- Last Synced: 2024-10-19T16:49:27.985Z (3 months ago)
- Language: Go
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cache elasticsearch adapter
[![Go Reference](https://pkg.go.dev/badge/github.com/morkid/gocache-elasticsearch/v7.svg)](https://pkg.go.dev/github.com/morkid/gocache-elasticsearch/v7)
[![Go](https://github.com/morkid/gocache-elasticsearch/actions/workflows/go.yml/badge.svg)](https://github.com/morkid/gocache-elasticsearch/actions/workflows/go.yml)
[![Build Status](https://travis-ci.com/morkid/gocache-elasticsearch.svg?branch=master)](https://travis-ci.com/morkid/gocache-elasticsearch)
[![Go Report Card](https://goreportcard.com/badge/github.com/morkid/gocache-elasticsearch/v7)](https://goreportcard.com/report/github.com/morkid/gocache-elasticsearch/v7)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/morkid/gocache-elasticsearch)](https://github.com/morkid/gocache-elasticsearch/releases)This library is created by implementing [gocache](https://github.com/morkid/gocache)
and require [elasticsearch](https://github.com/elastic/go-elasticsearch) v7.## Installation
```bash
go get -d github.com/morkid/gocache-elasticsearch/v7
```Available versions:
- [github.com/morkid/gocache-elasticsearch/v7](https://github.com/morkid/gocache-elasticsearch/tree/v7) for [elasticsearch client v7](https://github.com/elastic/go-elasticsearch/tree/v7)
- [github.com/morkid/gocache-elasticsearch/v6](https://github.com/morkid/gocache-elasticsearch/tree/v6) for [elasticsearch client v6](https://github.com/elastic/go-elasticsearch/tree/v6)
- [github.com/morkid/gocache-elasticsearch/v5](https://github.com/morkid/gocache-elasticsearch/tree/v5) for [elasticsearch client v5](https://github.com/elastic/go-elasticsearch/tree/v5)## Example usage
```go
package mainimport (
"time"
"fmt"
cache "github.com/morkid/gocache-elasticsearch/v7"
"github.com/elastic/go-elasticsearch/v7"
)func latency() {
// network latency simulation
// just for testing
time.Sleep(1 * time.Second)
}func main() {
config := elasticsearch.Config{
Addresses: []string{
"http://localhost:9200",
},
}
es, err := elasticsearch.NewClient(config)
if nil != err {
panic(err)
}adapterConfig := cache.ElasticCacheConfig{
Client: es,
Index: "example",
ExpiresIn: 10 * time.Second,
}adapter := *cache.NewElasticCache(config)
adapter.Set("foo", "bar")if adapter.IsValid("foo") {
value, err := adapter.Get("foo")
if nil != err {
fmt.Println(err)
} else if value != "bar" {
fmt.Println("value not equals to bar")
} else {
fmt.Println(value)
}
adapter.Clear("foo")latency()
if adapter.IsValid("foo") {
fmt.Println("Failed to remove key foo")
}
}
}```
## License
Published under the [MIT License](https://github.com/morkid/gocache-elasticsearch/blob/master/LICENSE).