Documentation
¶
Overview ¶
Package imagecache is the privacy proxy's store for remote mail images: a directory of files named by their URL's hash, shared by all messages, bounded in size and evicted least recently used first. Get downloads an image once (through imagefetch: public hosts, no cookies, no Referer) and serves it from disk after that, offline too.
Index ¶
- Constants
- Variables
- func AvatarKey(source, identity string) string
- func Key(src string) string
- type Cache
- func (c *Cache) AvatarGeneration() int
- func (c *Cache) AvatarMiss(key string) bool
- func (c *Cache) AvatarUnreachable(key string) bool
- func (c *Cache) Cached(src string) bool
- func (c *Cache) Clear() error
- func (c *Cache) Close()
- func (c *Cache) Dims(src string) (width, height int, ok bool)
- func (c *Cache) FallbackAvatar(ctx context.Context, key string, gen int) (Image, bool, error)
- func (c *Cache) ForgetFailure(src string)
- func (c *Cache) Get(ctx context.Context, src string) (Image, error)
- func (c *Cache) GetAvatar(ctx context.Context, src, source string, gen int) (Image, error)
- func (c *Cache) GetFile(ctx context.Context, src string) (path, format string, width, height int, err error)
- func (c *Cache) LookupAvatar(ctx context.Context, key string) (Image, bool, error)
- func (c *Cache) PruneUnused(cutoff time.Time) int
- func (c *Cache) PutAvatar(ctx context.Context, key string, data []byte, source string, gen int) (Image, error)
- func (c *Cache) RememberAvatarMiss(key string, gen int) error
- func (c *Cache) RememberAvatarUnreachable(key string, gen int)
- func (c *Cache) Size() int64
- type Image
- type NotStoredError
Constants ¶
const ( MaxBytes = 256 << 20 // the cache's size GlobalJobs = 8 // downloads at once HostJobs = 3 // downloads at once from one host )
Limits of the fetching proxy.
Variables ¶
var ErrClosed = errors.New("image cache is closed")
ErrClosed is returned by Get after Close.
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a directory of images; it is safe for concurrent use.
func Open ¶
Open is the cache in dir (made if need be), at most max bytes (MaxBytes when 0), downloading with client.
func (*Cache) AvatarGeneration ¶ added in v0.3.0
AvatarGeneration captures the Clear boundary before an avatar discovery starts.
func (*Cache) AvatarMiss ¶ added in v0.3.0
AvatarMiss reports a persistent deterministic miss, for at most 24 hours.
func (*Cache) AvatarUnreachable ¶ added in v0.3.0
AvatarUnreachable reports a discovery for key that failed short of a miss (no connection, a timeout) within the last few minutes, as Get does for URLs.
func (*Cache) Close ¶
func (c *Cache) Close()
Close cancels the downloads in flight and waits for them; Get fails after.
func (*Cache) FallbackAvatar ¶ added in v0.3.0
FallbackAvatar revalidates an ordinary avatar after a failed refresh, without changing its age. BIMI and entries invalidated by Clear are never returned.
func (*Cache) ForgetFailure ¶ added in v1.16.0
ForgetFailure lets the next Get of src try again at once, though src failed within failedTTL: an explicit retry.
func (*Cache) Get ¶
Get is src's image: from disk, or downloaded now (once, however many ask at the same time). A download goes on when its caller gives up, so the next ask finds it; a URL that failed fails at once for a few minutes.
func (*Cache) GetAvatar ¶ added in v0.3.0
GetAvatar shares the ordinary cache's jobs, singleflight and lifecycle. The first caller's deadline bounds the shared download; cancellation stops waiting. gen is captured before discovery, so Clear also blocks its later candidate downloads.
func (*Cache) GetFile ¶ added in v1.36.0
func (c *Cache) GetFile(ctx context.Context, src string) (path, format string, width, height int, err error)
GetFile is Get returning the cached file's path on disk instead of reading its bytes on every hit; *NotStoredError when it could not be stored.
func (*Cache) LookupAvatar ¶ added in v0.3.0
LookupAvatar reads only a fresh, revalidated avatar entry, without networking.
func (*Cache) PruneUnused ¶ added in v1.35.0
PruneUnused deletes every cached image that has not been read since cutoff, and reports how many it deleted. A read stamps the file, so the age survives a restart. A remembered miss is left to evict.
func (*Cache) PutAvatar ¶ added in v0.3.0
func (c *Cache) PutAvatar(ctx context.Context, key string, data []byte, source string, gen int) (Image, error)
PutAvatar stores validated bytes only if the cache has not been cleared since gen.
func (*Cache) RememberAvatarMiss ¶ added in v0.3.0
RememberAvatarMiss stores a definitive miss within the discovery's Clear boundary.
func (*Cache) RememberAvatarUnreachable ¶ added in v0.3.0
RememberAvatarUnreachable notes such a failure, unless the cache was cleared since gen.
type Image ¶
type Image struct {
Data []byte
Format string // png, jpeg, gif, webp; avatar entries also allow svg
Width, Height int
}
Image is a cached image.
type NotStoredError ¶ added in v1.36.0
type NotStoredError struct{ Image Image }
NotStoredError is GetFile's image that downloaded but could not be stored (a full disk, a Clear meanwhile): its bytes are here, with no file.
func (*NotStoredError) Error ¶ added in v1.36.0
func (e *NotStoredError) Error() string