storage

package
v0.0.0-...-68f58f5 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToContext

func ToContext(ctx context.Context, storage PackfileStorage) context.Context

ToContext sets the packfile storage for the client from the context.

Types

type InMemoryStorage

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

func NewInMemoryStorage

func NewInMemoryStorage(ctx context.Context, opts ...InMemoryStorageOption) *InMemoryStorage

func (*InMemoryStorage) Add

func (s *InMemoryStorage) Add(objs ...*protocol.PackfileObject)

func (*InMemoryStorage) Cleanup

func (s *InMemoryStorage) Cleanup()

Cleanup removes objects that haven't been accessed within the TTL period.

func (*InMemoryStorage) Delete

func (s *InMemoryStorage) Delete(key hash.Hash)

func (*InMemoryStorage) Get

func (*InMemoryStorage) GetAllKeys

func (s *InMemoryStorage) GetAllKeys() []hash.Hash

func (*InMemoryStorage) GetByType

func (s *InMemoryStorage) GetByType(key hash.Hash, objType protocol.ObjectType) (*protocol.PackfileObject, bool)

func (*InMemoryStorage) LastAccess

func (s *InMemoryStorage) LastAccess(key hash.Hash) (time.Time, bool)

LastAccess returns the last access time for a given key. If the key doesn't exist or TTL is not enabled, returns zero time and false.

func (*InMemoryStorage) Len

func (s *InMemoryStorage) Len() int

type InMemoryStorageOption

type InMemoryStorageOption func(*InMemoryStorage)

func WithTTL

func WithTTL(ttl time.Duration) InMemoryStorageOption

type NoopPackfileStorage

type NoopPackfileStorage struct{}

NoopPackfileStorage is a no-op implementation of PackfileStorage.

func (*NoopPackfileStorage) Add

func (n *NoopPackfileStorage) Add(objs ...*protocol.PackfileObject)

func (*NoopPackfileStorage) Delete

func (n *NoopPackfileStorage) Delete(key hash.Hash)

func (*NoopPackfileStorage) Get

func (*NoopPackfileStorage) GetAllKeys

func (n *NoopPackfileStorage) GetAllKeys() []hash.Hash

func (*NoopPackfileStorage) Len

func (n *NoopPackfileStorage) Len() int

type PackfileStorage

type PackfileStorage interface {
	// Get retrieves an object by its hash.
	Get(key hash.Hash) (*protocol.PackfileObject, bool)
	// GetByType retrieves an object by its hash and type.
	GetByType(key hash.Hash, objType protocol.ObjectType) (*protocol.PackfileObject, bool)
	// GetAllKeys returns all keys in the storage.
	GetAllKeys() []hash.Hash
	// Add adds objects to the storage.
	Add(objs ...*protocol.PackfileObject)
	// Delete deletes an object from the storage.
	Delete(key hash.Hash)
	// Len returns the number of objects in the storage.
	Len() int
}

PackfileStorage is an interface for storing packfile objects.

func FromContext

func FromContext(ctx context.Context) PackfileStorage

FromContext gets the packfile storage from the context.

func FromContextOrInMemory

func FromContextOrInMemory(ctx context.Context) (context.Context, PackfileStorage)

FromContextOrInMemory creates a new in-memory storage if the storage is not set in the context.

Jump to

Keyboard shortcuts

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