cache

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const ConfigType = "cache"

ConfigType is the type name for the cache keeper.

Variables

This section is empty.

Functions

func Builder

func Builder(ctx context.Context, c any) (secrets.Keeper, error)

Builder creates a new cache keeper from the given configuration.

func Validate

func Validate(ctx context.Context, c any) error

Validate checks that the configuration is correct for the cache keeper. It will check that the wrapped keeper to cache exists.

Types

type Cache

type Cache struct {
	secrets.Keeper // the secret keeper to cache
	*memory.Memory // the memory keeper used to store cached secrets
	// contains filtered or unexported fields
}

Cache is a secret keeper that wraps another secret keeper and caches secrets in memory. Writing to it directly is not permitted.

func New

func New(k secrets.Keeper, touchOnRead bool) (*Cache, error)

New creates a new caching secret keeper. The keeper will cache secrets in memory and will wrap the given secret keeper. The touchOnRead flag will cause the last modified date of secrets to be updated on GetSecret* calls.

func (*Cache) CopySecret

func (c *Cache) CopySecret(context.Context, string, string) (secrets.Secret, error)

CopySecret cannot be used and always fails with an error.

func (*Cache) DeleteSecret

func (c *Cache) DeleteSecret(ctx context.Context, id string) error

DeleteSecret deletes the secret with the given ID from the cache only. This does not delete the secret from the wrapped secret keeper.

func (*Cache) GetSecret

func (c *Cache) GetSecret(ctx context.Context, id string) (secrets.Secret, error)

GetSecret returns the secret with the given ID from the wrapped secret keeper on first call. Subsequent calls will return the cached secret. If the touchOnRead flag is set, the last modified date of the secret will be updated on each call.

func (*Cache) GetSecretsByName

func (c *Cache) GetSecretsByName(ctx context.Context, name string) ([]secrets.Secret, error)

GetSecretsByName returns the list of secrets with the given name from the wrapped secret keeper on first call. Subsequent calls will return the cached list of secrets. If the touchOnRead flag is set, the last modified date of the secrets will be updated on each call.

func (*Cache) ListLocations

func (c *Cache) ListLocations(ctx context.Context) ([]string, error)

ListLocations returns the list of locations in the wrapped secret keeper.

func (*Cache) ListSecrets

func (c *Cache) ListSecrets(ctx context.Context, loc string) ([]string, error)

ListSecrets returns the list of secrets in the wrapped secret keeper.

func (*Cache) MoveSecret

func (c *Cache) MoveSecret(context.Context, string, string) (secrets.Secret, error)

MoveSecret cannot be used and always fails with an error.

func (*Cache) SetSecret

func (c *Cache) SetSecret(context.Context, secrets.Secret) (secrets.Secret, error)

SetSecret cannot be used and always fails with an error.

type Config

type Config struct {
	// Keeper is the name of the keeper to cache.
	Keeper string `mapstructure:"keeper"`

	// TouchOnRead will cause the last modified date of secrets to be updated
	// on GetSecret* calls.
	TouchOnRead bool `mapstructure:"touch_on_read"`
}

Config is the configuration for the cache keeper.

Jump to

Keyboard shortcuts

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