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) 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) LookupAvatar(ctx context.Context, key string) (Image, bool, error)
- 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
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) 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) LookupAvatar ¶ added in v0.3.0
LookupAvatar reads only a fresh, revalidated avatar entry, without networking.
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.