cache

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = fmt.Errorf("secret not found in keyring")
)

Functions

This section is empty.

Types

type NoopLocker added in v1.13.0

type NoopLocker struct {
}

NoopLocker has empty implementation of Locker interface

func (*NoopLocker) Lock added in v1.13.0

func (*NoopLocker) Lock()

func (*NoopLocker) Unlock added in v1.13.0

func (*NoopLocker) Unlock()

type TokenCache

type TokenCache interface {
	// SaveToken saves the token securely to cache.
	SaveToken(token *oauth2.Token) error

	// GetToken retrieves the token from the cache.
	GetToken() (*oauth2.Token, error)

	// PurgeIfEquals purges the token from the cache.
	PurgeIfEquals(t *oauth2.Token) (bool, error)

	// Lock the cache.
	Lock()

	// TryLock tries to lock the cache.
	TryLock() bool

	// Unlock the cache.
	Unlock()

	// CondWait waits for the condition to be true.
	CondWait()

	// CondSignalCondBroadcast signals the condition.
	CondBroadcast()
}

TokenCache defines the interface needed to cache and retrieve oauth tokens.

type TokenCacheInMemoryProvider

type TokenCacheInMemoryProvider struct {
	// contains filtered or unexported fields
}

func NewTokenCacheInMemoryProvider added in v1.13.0

func NewTokenCacheInMemoryProvider() *TokenCacheInMemoryProvider

func (*TokenCacheInMemoryProvider) CondBroadcast added in v1.13.0

func (t *TokenCacheInMemoryProvider) CondBroadcast()

CondBroadcast signals the condition.

func (*TokenCacheInMemoryProvider) CondWait added in v1.13.0

func (t *TokenCacheInMemoryProvider) CondWait()

CondWait adds the current go routine to the condition waitlist and waits for another go routine to notify using CondBroadcast The current usage is that one who was able to acquire the lock using TryLock is the one who gets a valid token and notifies all the waitlist requesters so that they can use the new valid token. It also locks the Locker in the condition variable as the semantics of Wait is that it unlocks the Locker after adding the consumer to the waitlist and before blocking on notification. We use the condLocker which is noOp locker to get added to waitlist for notifications. The underlying notifcationList doesn't need to be guarded as it implementation is atomic and is thread safe Refer https://go.dev/src/runtime/sema.go Following is the function and its comments notifyListAdd adds the caller to a notify list such that it can receive notifications. The caller must eventually call notifyListWait to wait for such a notification, passing the returned ticket number.

func notifyListAdd(l *notifyList) uint32 {
	// This may be called concurrently, for example, when called from
	// sync.Cond.Wait while holding a RWMutex in read mode.
	return l.wait.Add(1) - 1
}

func (*TokenCacheInMemoryProvider) GetToken

func (t *TokenCacheInMemoryProvider) GetToken() (*oauth2.Token, error)

func (*TokenCacheInMemoryProvider) Lock added in v1.13.0

func (t *TokenCacheInMemoryProvider) Lock()

func (*TokenCacheInMemoryProvider) PurgeIfEquals added in v1.13.0

func (t *TokenCacheInMemoryProvider) PurgeIfEquals(existing *oauth2.Token) (bool, error)

func (*TokenCacheInMemoryProvider) SaveToken

func (t *TokenCacheInMemoryProvider) SaveToken(token *oauth2.Token) error

func (*TokenCacheInMemoryProvider) TryLock added in v1.13.0

func (t *TokenCacheInMemoryProvider) TryLock() bool

func (*TokenCacheInMemoryProvider) Unlock added in v1.13.0

func (t *TokenCacheInMemoryProvider) Unlock()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL