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, data []byte) (string, error)
- func (s *Store) Close(ctx context.Context) error
- func (s *Store) Get(ctx context.Context, key string) ([]byte, error)
- func (s *Store) Size(ctx context.Context, key string) (int64, 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. Content-addressed 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) 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.