usercache

package
Version: v0.0.0-...-1f1f7e6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2021 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Add(gimlet.User) error
	Put(gimlet.User) (string, error)
	Clear(gimlet.User, bool) error
	GetOrCreate(gimlet.User) (gimlet.User, error)
	Get(token string) (u gimlet.User, valid bool, err error)
	Find(id string) (u gimlet.User, valid bool, err error)
}

func NewExternal

func NewExternal(opts ExternalOptions) (Cache, error)

NewExternal returns an external user cache.

func NewInMemory

func NewInMemory(ctx context.Context, ttl time.Duration) Cache

NewInMemory returns a user cache which keeps entries in memory.

type ClearUserToken

type ClearUserToken func(u gimlet.User, all bool) error

ClearUserToken is a function provided by the client to remove users' tokens from cache. Passing true will ignore the user passed and clear all users.

type ExternalCache

type ExternalCache struct {
	Opts ExternalOptions
}

func (*ExternalCache) Add

func (c *ExternalCache) Add(u gimlet.User) error

func (*ExternalCache) Clear

func (c *ExternalCache) Clear(u gimlet.User, all bool) error

func (*ExternalCache) Find

func (c *ExternalCache) Find(id string) (gimlet.User, bool, error)

func (*ExternalCache) Get

func (c *ExternalCache) Get(token string) (gimlet.User, bool, error)

func (*ExternalCache) GetOrCreate

func (c *ExternalCache) GetOrCreate(u gimlet.User) (gimlet.User, error)

func (*ExternalCache) Put

func (c *ExternalCache) Put(u gimlet.User) (string, error)

type ExternalOptions

type ExternalOptions struct {
	PutUserGetToken PutUserGetToken
	GetUserByToken  GetUserByToken
	ClearUserToken  ClearUserToken
	GetUserByID     GetUserByID
	GetOrCreateUser GetOrCreateUser
}

ExternalOptions provides functions to inject the functionality of the user cache from an external source.

func (ExternalOptions) Validate

func (opts ExternalOptions) Validate() error

type GetOrCreateUser

type GetOrCreateUser func(gimlet.User) (gimlet.User, error)

GetOrCreateUser is a function provided by the client to get a user from persistent storage, or if the user does not exist, to create and save it.

type GetUserByID

type GetUserByID func(string) (u gimlet.User, valid bool, err error)

GetUserByID is a function provided by the client to get a user from persistent storage.

type GetUserByToken

type GetUserByToken func(string) (u gimlet.User, valid bool, err error)

GetUserByToken is a function provided by the client to retrieve cached users by token. It returns an error if and only if there was an error retrieving the user from the cache. It returns (<user>, true, nil) if the user is present in the cache and is valid. It returns (<user>, false, nil) if the user is present in the cache but has expired. It returns (nil, false, nil) if the user is not present in the cache.

type PutUserGetToken

type PutUserGetToken func(gimlet.User) (string, error)

PutUserGetToken returns a new token. Updating the user's TTL should happen in this function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL