cache

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package cache is a two-layer, pure-Go SQLite store that makes repeated extraction cheap and keeps sec-cli a good EDGAR citizen by not re-fetching bytes it already has.

It wraps the fetch seam rather than living inside internal/edgar, so both packages stay single-purpose: edgar is a pure HTTP client, cache is a pure key/value store. The two layers key on two different things:

  • The raw layer caches the bytes of every EDGAR fetch by URL. EDGAR documents for a filed accession are immutable, so a URL hit is permanently valid — there is no TTL.
  • The parsed layer caches the assembled model.Document (as canonical JSON) by accession + model.ParserVersion. A parser fix bumps ParserVersion and transparently invalidates parsed output while the raw bytes stay warm, so re-parsing costs no network.

The driver is modernc.org/sqlite (pure Go) so CGO_ENABLED=0 builds keep working on every platform.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath is the cache file location under the OS cache directory: <os.UserCacheDir>/sec-cli/cache.db.

Types

type Cache

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

Cache is the two-layer store. The zero value (and any nil *Cache) is a valid no-op cache: every Get misses and every Put is silently dropped, which is how --no-cache and hermetic tests bypass persistence. A Cache opened with Open is backed by a SQLite file; close it with Close.

func NoOp

func NoOp() *Cache

NoOp returns a cache that stores nothing: every lookup misses and every write is dropped. Used for --no-cache and tests that want the pipeline shape without touching disk.

func Open

func Open(path string) (*Cache, error)

Open opens (creating if absent) the SQLite cache at path, creating the parent directory as needed, and runs migrations gated on PRAGMA user_version. Pass DefaultPath() for the standard location.

func (*Cache) Clear

func (c *Cache) Clear() error

Clear truncates both layers, leaving an empty but valid cache. It is safe to call on a no-op cache.

func (*Cache) Close

func (c *Cache) Close() error

Close releases the underlying database. It is safe to call on a no-op cache.

func (*Cache) Fetching

func (c *Cache) Fetching(fetch FetchFunc) FetchFunc

Fetching wraps fetch so a URL is fetched at most once: it checks the raw layer first and populates it on a miss. This is what the pipeline composes around edgar.Client.Get — edgar itself is never modified. A no-op cache returns fetch unchanged in effect (every call misses and nothing is stored).

func (*Cache) GetDocument

func (c *Cache) GetDocument(accession string) (*model.Document, bool)

GetDocument returns the cached Document for accession under the current model.ParserVersion and model.SchemaVersion. A document cached under a different parser or schema version misses, so either a parser fix or a schema bump invalidates parsed output without touching the raw layer.

func (*Cache) GetRaw

func (c *Cache) GetRaw(url string) ([]byte, bool)

GetRaw returns the cached bytes for url and whether they were present. A no-op cache always misses.

func (*Cache) Path

func (c *Cache) Path() string

Path returns the cache file location, or "" for a no-op cache.

func (*Cache) PutDocument

func (c *Cache) PutDocument(accession string, doc *model.Document) error

PutDocument stores doc as canonical JSON keyed on accession, model.ParserVersion, and model.SchemaVersion. A no-op cache drops the write.

func (*Cache) PutRaw

func (c *Cache) PutRaw(url string, body []byte) error

PutRaw stores body under url. EDGAR bytes for a filed accession are immutable, so an existing entry is overwritten harmlessly. A no-op cache drops the write.

type FetchFunc

type FetchFunc func(ctx context.Context, url string) ([]byte, error)

FetchFunc is the fetch seam the cache wraps: the shape of edgar.Client.Get.

Jump to

Keyboard shortcuts

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