1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-11-23 21:44:41 +02:00

Add simple in-memory cache (#2231)

* Add simple in-memory cache

* Support configuring cache expiration duration

* Support preinitializing cache with items

* Register cache
This commit is contained in:
Niek den Breeje
2021-08-31 16:31:16 +02:00
committed by GitHub
parent dd0a7746ff
commit 05a299b76c
8 changed files with 357 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import (
"github.com/asim/go-micro/v3/auth"
"github.com/asim/go-micro/v3/broker"
"github.com/asim/go-micro/v3/cache"
"github.com/asim/go-micro/v3/client"
"github.com/asim/go-micro/v3/config"
"github.com/asim/go-micro/v3/debug/profile"
@@ -265,6 +266,8 @@ var (
}
DefaultConfigs = map[string]func(...config.Option) (config.Config, error){}
DefaultCaches = map[string]func(...cache.Option) cache.Cache{}
)
func init() {
@@ -285,6 +288,7 @@ func newCmd(opts ...Option) Cmd {
Tracer: &trace.DefaultTracer,
Profile: &profile.DefaultProfile,
Config: &config.DefaultConfig,
Cache: &cache.DefaultCache,
Brokers: DefaultBrokers,
Clients: DefaultClients,
@@ -298,6 +302,7 @@ func newCmd(opts ...Option) Cmd {
Auths: DefaultAuths,
Profiles: DefaultProfiles,
Configs: DefaultConfigs,
Caches: DefaultCaches,
}
for _, o := range opts {