Documentation
¶
Index ¶
- func NewInCache(db blob.Store) blob.Store
- func NewStorageCache(storage blob.ObjectStorage, minRemaining time.Duration) blob.ObjectStorage
- type Cache
- func (c *Cache) Advance(ctx context.Context, id *blobpb.BlobId, to blob.State, ...) (bool, error)
- func (c *Cache) AttachRenditions(ctx context.Context, id *blobpb.BlobId, refs []blob.RenditionRef) error
- func (c *Cache) ClaimForFinalization(ctx context.Context, id *blobpb.BlobId, asOf, until time.Time) (bool, error)
- func (c *Cache) CreatePending(ctx context.Context, b *blob.Blob) error
- func (c *Cache) DelayFinalization(ctx context.Context, id *blobpb.BlobId, nextAttemptAt time.Time) error
- func (c *Cache) GetByID(ctx context.Context, id *blobpb.BlobId) (*blob.Blob, error)
- func (c *Cache) GetByIDs(ctx context.Context, ids []*blobpb.BlobId) ([]*blob.Blob, error)
- func (c *Cache) GetDueForFinalization(ctx context.Context, kind blob.ContentKind, asOf time.Time, limit int) ([]*blob.FinalizationTask, error)
- func (c *Cache) GetFinalizationQueueStats(ctx context.Context, kind blob.ContentKind) (*blob.FinalizationQueueStats, error)
- func (c *Cache) MarkForFinalization(ctx context.Context, id *blobpb.BlobId, kind blob.ContentKind, ...) error
- func (c *Cache) Reject(ctx context.Context, id *blobpb.BlobId, rejection *blob.RejectionMetadata) (bool, error)
- type StorageCache
- func (c *StorageCache) CopyToOrigin(ctx context.Context, key string) error
- func (c *StorageCache) DeleteUpload(ctx context.Context, key string) error
- func (c *StorageCache) GetUploaded(ctx context.Context, key string) ([]byte, error)
- func (c *StorageCache) PresignUpload(ctx context.Context, key, mimeType string, sizeBytes uint64) (*blobpb.UploadTarget, error)
- func (c *StorageCache) PutOrigin(ctx context.Context, key, mimeType string, data []byte) error
- func (c *StorageCache) SignDownloadURL(ctx context.Context, key string) (*blobpb.DownloadUrl, error)
- func (c *StorageCache) UploadExists(ctx context.Context, key string) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewInCache ¶
NewInCache returns a blob.Store that caches terminal blob records in front of db. It composes over any backing implementation.
func NewStorageCache ¶ added in v1.22.0
func NewStorageCache(storage blob.ObjectStorage, minRemaining time.Duration) blob.ObjectStorage
NewStorageCache returns a blob.ObjectStorage that caches signed download URLs in front of storage.
minRemaining is the validity a cached URL is guaranteed to have left when it is handed out: an entry is only cached for its lifetime MINUS this margin, so it is re-minted before it can be served close to expiry. Set it comfortably above the time a client might sit on the URL before fetching (it must not receive one that expires mid-download); the cost of a larger margin is only a lower hit rate. A minRemaining at or above the signer's TTL disables caching entirely, since no entry could satisfy it.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache wraps a blob.Store, caching only blobs that have reached a terminal state (Ready or Rejected).
func (*Cache) AttachRenditions ¶ added in v1.22.0
func (*Cache) ClaimForFinalization ¶ added in v1.22.0
func (*Cache) CreatePending ¶
func (*Cache) DelayFinalization ¶ added in v1.22.0
func (*Cache) GetDueForFinalization ¶ added in v1.22.0
func (*Cache) GetFinalizationQueueStats ¶ added in v1.22.0
func (c *Cache) GetFinalizationQueueStats(ctx context.Context, kind blob.ContentKind) (*blob.FinalizationQueueStats, error)
func (*Cache) MarkForFinalization ¶ added in v1.22.0
type StorageCache ¶ added in v1.22.0
type StorageCache struct {
// contains filtered or unexported fields
}
StorageCache wraps a blob.ObjectStorage, caching the signed download URLs it mints. Every other operation passes straight through.
Signing is the expensive part of resolving a blob: a CloudFront signed URL costs an RSA signature (~0.7ms), and a single chat feed page resolves one per member's avatar. Caching it matters because a download URL is NOT per-viewer — it signs the object's path and an expiry, nothing about who asked — so the URL minted for one reader is byte-identical to the one every other reader would get. The bytes behind a key are immutable too, so a cached URL can never point at stale content.
Upload targets are deliberately NOT cached: a presigned upload is a bearer credential minted per reservation, pinned to that upload's key, MIME type and exact size, and reusing one across uploads would be wrong.
func (*StorageCache) CopyToOrigin ¶ added in v1.22.0
func (c *StorageCache) CopyToOrigin(ctx context.Context, key string) error
func (*StorageCache) DeleteUpload ¶ added in v1.22.0
func (c *StorageCache) DeleteUpload(ctx context.Context, key string) error
func (*StorageCache) GetUploaded ¶ added in v1.22.0
func (*StorageCache) PresignUpload ¶ added in v1.22.0
func (c *StorageCache) PresignUpload(ctx context.Context, key, mimeType string, sizeBytes uint64) (*blobpb.UploadTarget, error)
func (*StorageCache) SignDownloadURL ¶ added in v1.22.0
func (c *StorageCache) SignDownloadURL(ctx context.Context, key string) (*blobpb.DownloadUrl, error)
SignDownloadURL returns a cached signed URL for key when one is held with enough life left in it, and otherwise mints and caches a fresh one. The returned proto is a copy, so a caller mutating it cannot corrupt the cached entry.