sharedcache

package
v1.62.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

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
)

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