sharedcache

package
v1.94.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func CacheTypeStrings added in v1.90.0

func CacheTypeStrings() []string

CacheTypeStrings returns a slice of all String values of the enum

func GenerateKey

func GenerateKey(elems ...string) string

GenerateKey generates a key based on a list of key elements `elems`.

func TransferFiles

func TransferFiles(ctx context.Context, fs filesystem.FS, dst, src string) (destFile string, err error)

TransferFiles transfers a file from a location `src` to another `dest` and ensures the integrity (i.e. hash validation) of what was copied across. `dest` can be a file or a directory. If not existent, it will be created on the fly. non-existent directory path should be terminated by a path separator i.e. / or \

Types

type AbstractSharedCacheRepository

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

AbstractSharedCacheRepository defines an abstract cache repository.

func NewAbstractSharedCacheRepository

func NewAbstractSharedCacheRepository(cfg *Configuration, fs filesystem.FS) (cache *AbstractSharedCacheRepository, err error)

func (*AbstractSharedCacheRepository) EntriesCount

func (c *AbstractSharedCacheRepository) EntriesCount(ctx context.Context) (count int64, err error)

func (*AbstractSharedCacheRepository) GenerateKey

func (c *AbstractSharedCacheRepository) GenerateKey(elems ...string) string

func (*AbstractSharedCacheRepository) GetEntries

func (c *AbstractSharedCacheRepository) GetEntries(ctx context.Context) (entries []string, err error)

func (*AbstractSharedCacheRepository) RemoveEntry

func (c *AbstractSharedCacheRepository) RemoveEntry(ctx context.Context, key string) error

type CacheType

type CacheType int
const (
	CacheMutable CacheType = iota
	CacheImmutable
)

func CacheTypeString added in v1.90.0

func CacheTypeString(s string) (CacheType, error)

CacheTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func CacheTypeValues added in v1.90.0

func CacheTypeValues() []CacheType

CacheTypeValues returns all values of the enum

func (CacheType) IsACacheType added in v1.90.0

func (i CacheType) IsACacheType() bool

IsACacheType returns "true" if the value is listed in the enum definition. "false" otherwise

func (CacheType) MarshalJSON added in v1.90.0

func (i CacheType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for CacheType

func (CacheType) MarshalText added in v1.90.0

func (i CacheType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for CacheType

func (CacheType) MarshalYAML added in v1.90.0

func (i CacheType) MarshalYAML() (interface{}, error)

MarshalYAML implements a YAML Marshaler for CacheType

func (CacheType) String added in v1.90.0

func (i CacheType) String() string

func (*CacheType) UnmarshalJSON added in v1.90.0

func (i *CacheType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for CacheType

func (*CacheType) UnmarshalText added in v1.90.0

func (i *CacheType) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for CacheType

func (*CacheType) UnmarshalYAML added in v1.90.0

func (i *CacheType) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements a YAML Unmarshaler for CacheType

type Configuration

type Configuration struct {
	RemoteStoragePath       string        `mapstructure:"remote_storage_path"` // Path where the cache will be stored.
	Timeout                 time.Duration `mapstructure:"timeout"`             // Cache timeout if need be
	FilesystemItemsToIgnore string        `mapstructure:"ignore_fs_items"`     // List of files/folders to ignore (pattern list separated by commas)
}

func DefaultSharedCacheConfiguration

func DefaultSharedCacheConfiguration() *Configuration

func (*Configuration) Validate

func (cfg *Configuration) Validate() error

type FileWithModTime

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

type ISharedCacheRepository

type ISharedCacheRepository interface {
	// GenerateKey generates a unique key based on key elements `elems`.
	GenerateKey(elems ...string) string
	// Fetch downloads and installs files from the cache[`key`] to `dest`.
	Fetch(ctx context.Context, key, dest string) error
	// Store uploads files from `src` to cache[`key`].
	Store(ctx context.Context, key, src string) error
	// CleanEntry cleans up cache[`key`]. The key is still present in the cache.
	CleanEntry(ctx context.Context, key string) error
	// RemoveEntry removes cache[`key`] entry. The key is then no longer present in the cache.
	RemoveEntry(ctx context.Context, key string) error
	// GetEntryAge returns the age of the cache[`key`] entry
	GetEntryAge(ctx context.Context, key string) (age time.Duration, err error)
	// SetEntryAge sets the age of the cache[`key`] entry. Mostly for testing.
	SetEntryAge(ctx context.Context, key string, age time.Duration) error
	// GetEntries returns all cache entries.
	GetEntries(ctx context.Context) (entries []string, err error)
	// EntriesCount returns cache entries count
	EntriesCount(ctx context.Context) (int64, error)
}

ISharedCacheRepository defines a cache stored on a remote location and shared by separate processes.

func NewCache

func NewCache(cacheType CacheType, fs filesystem.FS, cfg *Configuration) (ISharedCacheRepository, error)

func NewSharedMutableCacheRepository

func NewSharedMutableCacheRepository(cfg *Configuration, fs filesystem.FS) (repository ISharedCacheRepository, err error)

type SharedImmutableCacheRepository

type SharedImmutableCacheRepository struct {
	AbstractSharedCacheRepository
}

func NewSharedImmutableCacheRepository

func NewSharedImmutableCacheRepository(cfg *Configuration, fs filesystem.FS) (repository *SharedImmutableCacheRepository, err error)

func (*SharedImmutableCacheRepository) CleanEntry

func (s *SharedImmutableCacheRepository) CleanEntry(ctx context.Context, key string) (err error)

func (*SharedImmutableCacheRepository) Fetch

func (s *SharedImmutableCacheRepository) Fetch(ctx context.Context, key, dest string) (err error)

func (*SharedImmutableCacheRepository) GetEntryAge

func (s *SharedImmutableCacheRepository) GetEntryAge(ctx context.Context, key string) (age time.Duration, err error)

func (*SharedImmutableCacheRepository) SetEntryAge

func (s *SharedImmutableCacheRepository) SetEntryAge(ctx context.Context, key string, age time.Duration) error

func (*SharedImmutableCacheRepository) Store

func (s *SharedImmutableCacheRepository) Store(ctx context.Context, key, src string) (err error)

type SharedMutableCacheRepository

type SharedMutableCacheRepository struct {
	AbstractSharedCacheRepository
	// contains filtered or unexported fields
}

SharedMutableCacheRepository defines a shared cache using a distributed lock system solely based on lock files.

func (*SharedMutableCacheRepository) CleanEntry

func (s *SharedMutableCacheRepository) CleanEntry(ctx context.Context, key string) error

func (*SharedMutableCacheRepository) Fetch

func (s *SharedMutableCacheRepository) Fetch(ctx context.Context, key, dest string) (err error)

func (*SharedMutableCacheRepository) GetEntryAge

func (*SharedMutableCacheRepository) SetEntryAge

func (s *SharedMutableCacheRepository) SetEntryAge(ctx context.Context, key string, age time.Duration) error

func (*SharedMutableCacheRepository) Store

func (s *SharedMutableCacheRepository) Store(ctx context.Context, key, src string) (err error)

Jump to

Keyboard shortcuts

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