attachcache

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package attachcache stores attachment bytes on local disk.

Attachment bytes were proxied from Jira on every view, which contradicts the premise of the tool: everything else answers from local disk, and an issue with three screenshots re-downloaded them on every open. Bytes for a given attachment id are immutable in Jira, so they cache indefinitely and the only bound needed is total size.

A cached attachment also survives having no credential at all, which is what lets the bundled demo snapshot show real images offline.

Index

Constants

View Source
const DefaultMaxBytes int64 = 512 << 20

DefaultMaxBytes bounds the cache. Attachments are usually screenshots, so a few hundred megabytes holds a working set of thousands.

Variables

This section is empty.

Functions

func TooLarge

func TooLarge(err error) bool

TooLarge reports whether err means the entry was skipped for its size.

Types

type Cache

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

Cache is a content-addressed store under one directory. Safe for concurrent use; a miss for the same id collapses into a single fetch.

func New

func New(dir string, maxBytes int64) (*Cache, error)

New opens (and creates) a cache directory. maxBytes <= 0 means DefaultMaxBytes.

func (*Cache) Dir

func (c *Cache) Dir() string

Dir is the directory the cache owns.

func (*Cache) Fill

func (c *Cache) Fill(id string, fetch func() (io.ReadCloser, Meta, error)) error

Fill is the single-flight write path: fetch runs at most once per id even if ten renders miss at the same moment. It returns after the bytes are on disk.

fetch must return the body, its content type, and its length (0 if unknown).

func (*Cache) Get

func (c *Cache) Get(id string) (io.ReadSeekCloser, Meta, error)

Get returns an open reader for a cached attachment. The caller closes it. A miss returns os.ErrNotExist.

func (*Cache) Has

func (c *Cache) Has(id string) bool

Has reports whether an attachment is cached, without opening it.

func (*Cache) ImportFile

func (c *Cache) ImportFile(id, path, contentType, filename string) error

ImportFile seeds an entry from a local file. It exists for fixtures: the bundled demo snapshot ships attachment bytes so `gadak demo` shows real images with no Jira account, and a test can prime the cache without a fake server.

func (*Cache) Stats

func (c *Cache) Stats() (files int, bytes int64)

Stats reports the cache footprint, for the settings panel and `gadak status`.

type Meta

type Meta struct {
	ContentType string `json:"content_type"`
	Size        int64  `json:"size"`
	Filename    string `json:"filename,omitempty"`
}

Meta is the sidecar recorded next to each cached file. Content-Type has to survive a restart, and guessing it back from bytes is worse than storing it.

Jump to

Keyboard shortcuts

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