2019-05-31 00:22:43 +01:00
|
|
|
# Registry Cache
|
|
|
|
|
|
|
|
Cache is a library that provides a caching layer for the go-micro [registry](https://godoc.org/github.com/micro/go-micro/registry#Registry).
|
|
|
|
|
|
|
|
If you're looking for caching in your microservices use the [selector](https://micro.mu/docs/fault-tolerance.html#caching-discovery).
|
|
|
|
|
|
|
|
## Interface
|
|
|
|
|
2020-08-07 11:21:59 +01:00
|
|
|
```go
|
2019-05-31 00:22:43 +01:00
|
|
|
// Cache is the registry cache interface
|
|
|
|
type Cache interface {
|
|
|
|
// embed the registry interface
|
|
|
|
registry.Registry
|
|
|
|
// stop the cache watcher
|
|
|
|
Stop()
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2020-08-07 11:21:59 +01:00
|
|
|
```go
|
2020-08-07 11:22:57 +01:00
|
|
|
import "github.com/micro/go-micro/registry/cache"
|
2019-05-31 00:22:43 +01:00
|
|
|
|
2020-08-07 11:22:57 +01:00
|
|
|
# create a new cache
|
|
|
|
c := cache.New(registry)
|
2019-05-31 00:22:43 +01:00
|
|
|
|
2020-08-07 11:22:57 +01:00
|
|
|
# get a service from the cache
|
|
|
|
services, _ := c.GetService("helloworld")
|
2019-05-31 00:22:43 +01:00
|
|
|
```
|