Documentation
¶
Index ¶
- func ToContext(ctx context.Context, storage PackfileStorage) context.Context
- type InMemoryStorage
- func (s *InMemoryStorage) Add(objs ...*protocol.PackfileObject)
- func (s *InMemoryStorage) Cleanup()
- func (s *InMemoryStorage) Delete(key hash.Hash)
- func (s *InMemoryStorage) Get(key hash.Hash) (*protocol.PackfileObject, bool)
- func (s *InMemoryStorage) GetAllKeys() []hash.Hash
- func (s *InMemoryStorage) GetByType(key hash.Hash, objType protocol.ObjectType) (*protocol.PackfileObject, bool)
- func (s *InMemoryStorage) LastAccess(key hash.Hash) (time.Time, bool)
- func (s *InMemoryStorage) Len() int
- type InMemoryStorageOption
- type NoopPackfileStorage
- type PackfileStorage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 (s *InMemoryStorage) Get(key hash.Hash) (*protocol.PackfileObject, bool)
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 ¶
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 (n *NoopPackfileStorage) Get(key hash.Hash) (*protocol.PackfileObject, bool)
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.
Click to show internal directories.
Click to hide internal directories.