ghcache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package ghcache caches GitHub REST `GET` responses keyed by method, path, body, and token fingerprint, with method-aware write-through

Index

Constants

View Source
const (
	// TTL1Min covers fast-moving issue/PR/CI surfaces. Sized to absorb a
	// `watch -n 2` loop across ~10 repos (~10 calls/min, well under the
	TTL1Min = 1 * time.Minute

	// TTL10Min covers head-of-branch reads, ref/tree/content lookups,
	// and search. Slower turnover than issues; long enough to collapse
	TTL10Min = 10 * time.Minute

	// TTL1Hour covers repo-level metadata: the repo body, labels,
	// milestones, releases, tags, topics, languages, contributors,
	TTL1Hour = 1 * time.Hour

	// TTL25Hour covers the identity surface: user, org, teams. Picked
	// at 25 (not 24) hours so a daily cron always sees a miss across
	TTL25Hour = 25 * time.Hour
)

Default TTLs by tier. Exported so callers and tests can reference the same constants the path-classifier uses internally.

Variables

This section is empty.

Functions

func GetJSON

func GetJSON(path string, fetch func() ([]byte, error)) ([]byte, error)

GetJSON fetches the response body for a `GET <path>` GitHub REST call, served from cache if a fresh entry exists. On miss it invokes fetch

func Invalidate

func Invalidate(method, path string)

Invalidate drops cache entries that a `method <path>` write would affect. Idempotent and safe to call on paths that have no cached

func MaybeServe

func MaybeServe(path string) ([]byte, bool)

MaybeServe is the lookup-only half of the cache. Returns (cached bytes, true) on a fresh hit, (nil, false) on miss or unclassified

func MaybeServeMaxAge

func MaybeServeMaxAge(path string, maxAge time.Duration) ([]byte, bool)

MaybeServeMaxAge is the per-call-freshness variant of MaybeServe. Returns (cached bytes, true) only when a cached entry exists AND its

func Store

func Store(path string, data []byte) bool

Store puts data under path using the TTL derived from the path's tier. Returns false if the path is unclassified (caller should be

Types

This section is empty.

Jump to

Keyboard shortcuts

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