mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-06 17:08:53 +00:00
[management] Add redis cache (#3516)
Refactor IdP user data caching by introducing a Redis cache implementation alongside an in-memory fallback, adding a Marshaler interface for flexible serialization, and updating related tests and account management code. - Added a new cache store implementation with support for Redis and in-memory backends. - Introduced Marshaler and wrapper types for handling serialization with msgpack and JSON. - Updated account and user management modules to integrate and test the new caching strategy.
This commit is contained in:
35
management/server/cache/marshaler.go
vendored
Normal file
35
management/server/cache/marshaler.go
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/eko/gocache/lib/v4/store"
|
||||
)
|
||||
|
||||
type Marshaler interface {
|
||||
Get(ctx context.Context, key any, returnObj any) (any, error)
|
||||
Set(ctx context.Context, key, object any, options ...store.Option) error
|
||||
Delete(ctx context.Context, key any) error
|
||||
}
|
||||
|
||||
type cacher[T any] interface {
|
||||
Get(ctx context.Context, key any) (T, error)
|
||||
Set(ctx context.Context, key any, object T, options ...store.Option) error
|
||||
Delete(ctx context.Context, key any) error
|
||||
}
|
||||
|
||||
type marshalerWraper struct {
|
||||
cache cacher[any]
|
||||
}
|
||||
|
||||
func (m marshalerWraper) Get(ctx context.Context, key any, _ any) (any, error) {
|
||||
return m.cache.Get(ctx, key)
|
||||
}
|
||||
|
||||
func (m marshalerWraper) Set(ctx context.Context, key, object any, options ...store.Option) error {
|
||||
return m.cache.Set(ctx, key, object, options...)
|
||||
}
|
||||
|
||||
func (m marshalerWraper) Delete(ctx context.Context, key any) error {
|
||||
return m.cache.Delete(ctx, key)
|
||||
}
|
||||
Reference in New Issue
Block a user