blobcache

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package blobcache provides an httpcache.Cache implementation that uses Go Cloud Development Kit (CDK) blob storage for cloud-agnostic cache storage.

Supports multiple cloud providers:

  • Amazon S3
  • Google Cloud Storage
  • Azure Blob Storage
  • In-memory (for testing)
  • Local filesystem

Example usage with S3:

import (
    "context"
    _ "gocloud.dev/blob/s3blob"
    "github.com/sandrolain/httpcache/blobcache"
)

ctx := context.Background()
cache, err := blobcache.New(ctx, blobcache.Config{
    BucketURL: "s3://my-bucket?region=us-west-2",
    KeyPrefix: "httpcache/",
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, config Config) (httpcache.Cache, error)

New creates a new blob cache with the given configuration. The bucket is opened using the BucketURL. Call Close() to clean up resources when done.

func NewWithBucket

func NewWithBucket(bucket *blob.Bucket, keyPrefix string, timeout time.Duration) httpcache.Cache

NewWithBucket creates a cache using an already-opened bucket. The caller is responsible for closing the bucket.

Types

type Config

type Config struct {
	// BucketURL is the Go Cloud blob URL (e.g., "s3://bucket?region=us-west-2")
	BucketURL string

	// KeyPrefix is prepended to all cache keys (default: "cache/")
	KeyPrefix string

	// Timeout for blob operations (default: 30s)
	Timeout time.Duration

	// Bucket is an optional pre-opened bucket (if nil, BucketURL is used)
	Bucket *blob.Bucket
}

Config holds the configuration for the blob cache.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with default values.

Jump to

Keyboard shortcuts

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