Home Download Docs Code Community
import "perkeep/pkg/cacher"
Overview
Index

Overview ▾

Package cacher provides various blobref fetching caching mechanisms.

Index

type CachingFetcher
    func NewCachingFetcher(cache blobserver.Cache, fetcher blob.Fetcher) *CachingFetcher
    func (cf *CachingFetcher) Fetch(ctx context.Context, br blob.Ref) (content io.ReadCloser, size uint32, err error)
    func (cf *CachingFetcher) SetCacheHitHook(fn func(br blob.Ref, rc io.ReadCloser) (io.ReadCloser, error))
type DiskCache
    func NewDiskCache(fetcher blob.Fetcher) (*DiskCache, error)
    func (dc *DiskCache) Clean()

Package files

cacher.go

type CachingFetcher

type CachingFetcher struct {
    // contains filtered or unexported fields
}

A CachingFetcher is a blob.Fetcher and a blob.SeekFetcher.

func NewCachingFetcher

func NewCachingFetcher(cache blobserver.Cache, fetcher blob.Fetcher) *CachingFetcher

NewCachingFetcher returns a CachingFetcher that fetches from fetcher and writes to and serves from cache.

func (*CachingFetcher) Fetch

func (cf *CachingFetcher) Fetch(ctx context.Context, br blob.Ref) (content io.ReadCloser, size uint32, err error)

func (*CachingFetcher) SetCacheHitHook

func (cf *CachingFetcher) SetCacheHitHook(fn func(br blob.Ref, rc io.ReadCloser) (io.ReadCloser, error))

SetCacheHitHook sets a function that will modify the return values from Fetch in the case of a cache hit. Its purpose is to add potential side-effects from calling the Fetcher that would have happened if we had had a cache miss. It is the responsibility of fn to return a ReadCloser equivalent to the state that rc was given in.

type DiskCache

type DiskCache struct {
    *CachingFetcher

    // Root is the temp directory being used to store files.
    // It is available mostly for debug printing.
    Root string
    // contains filtered or unexported fields
}

A DiskCache is a blob.Fetcher that serves from a local temp directory and is backed by a another blob.Fetcher (usually the pkg/client HTTP client).

func NewDiskCache

func NewDiskCache(fetcher blob.Fetcher) (*DiskCache, error)

NewDiskCache returns a new DiskCache from a Fetcher, which is usually the pkg/client HTTP client (which typically has much higher latency and lower bandwidth than local disk).

func (*DiskCache) Clean

func (dc *DiskCache) Clean()

Clean cleans some or all of the DiskCache.

Website layout inspired by memcached.
Content by the authors.