imagecache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
var ErrClosed = errors.New("image cache is closed")

ErrClosed is returned by Get after Close.

Functions

func Key

func Key(src string) string

Key is the cache key of a URL: 32 hex digits of its SHA-256.

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

func Open(dir string, max int64, client *http.Client) (*Cache, error)

Open is the cache in dir (made if need be), at most max bytes (MaxBytes when 0), downloading with client.

func (*Cache) Cached

func (c *Cache) Cached(src string) bool

Cached reports whether src's image is on disk.

func (*Cache) Clear

func (c *Cache) Clear() error

Clear deletes every cached image.

func (*Cache) Close

func (c *Cache) Close()

Close cancels the downloads in flight and waits for them; Get fails after.

func (*Cache) Dims

func (c *Cache) Dims(src string) (width, height int, ok bool)

Dims is the size of src's image if it is cached; it reads no file.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, src string) (Image, error)

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) Size

func (c *Cache) Size() int64

Size is the bytes the cache takes on disk.

type Image

type Image struct {
	Data          []byte
	Format        string // as imagefetch.Dims names it: png, jpeg, gif or webp
	Width, Height int
}

Image is a cached image.

Jump to

Keyboard shortcuts

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