Documentation ¶
Overview ¶
Package wbstore implements a wrapper for a blob.CAS that caches writes of content-addressed data in a buffer and pushes them into a base store in the background.
Index ¶
- type Store
- func (s *Store) Buffer() blob.Store
- func (s *Store) CASPut(ctx context.Context, opts blob.CASPutOptions) (string, error)
- func (s *Store) Close(ctx context.Context) error
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) Get(ctx context.Context, key string) ([]byte, error)
- func (s *Store) Len(ctx context.Context) (int64, error)
- func (s *Store) List(ctx context.Context, start string, f func(string) error) error
- func (s *Store) Put(ctx context.Context, opts blob.PutOptions) error
- func (s *Store) Sync(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
A Store implements the blob.CAS interface delegated to an underlying (base) store. Non-replacement writes are cached locally in a buffer store, and written behind to the base store in the background. Get and Size queries respect the buffer cache, so that the local application sees a consistent view. Other store operations delegate directly to the base store.
This wrapper is intended for use with base store implementations that are remote and expensive to write to, such as cloud storage. This approach is suitable for applications that do not require immediate consistency of the base store.
func New ¶
New constructs a store wrapper that delegates to base and uses buf as the local buffer store. New will panic if base == nil or buf == nil. The ctx value governs the operation of the background writer, which will run until the store is closed or ctx terminates.
If the buffer store is not empty, any existing blobs will be mirrored to the base store. This allows the caller to gracefully resume after failures.
func (*Store) CASPut ¶
CASPut implements part of blob.CAS. It queries the base store for the content key, but stores the blob only in the buffer.
func (*Store) Close ¶
Close implements the optional blob.Closer interface. It signals the background writer to terminate, and blocks until it has done so or until ctx ends.
func (*Store) Delete ¶
Delete implements part of blob.Store. The key is deleted from both the buffer and the base store, and succeeds as long as either of those operations succeeds.
func (*Store) Get ¶
Get implements part of blob.Store. If key is in the write-behind store, its value there is returned; otherwise it is fetched from the base store.
func (*Store) Len ¶ added in v0.2.0
Len implements part of blob.Store. It merges contents from the buffer that are not listed in the underlying store, so that the reported length reflects the total number of unique keys across both the buffer and the base store.
func (*Store) List ¶ added in v0.2.0
List implements part of blob.Store. It merges contents from the buffer that are not listed in the underlying store, so that the keys reported include those that have not yet been written back.