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 ¶
- func DefaultPath() (string, error)
- type Cache
- func (c *Cache) Clear() error
- func (c *Cache) Close() error
- func (c *Cache) Fetching(fetch FetchFunc) FetchFunc
- func (c *Cache) GetDocument(accession string) (*model.Document, bool)
- func (c *Cache) GetRaw(url string) ([]byte, bool)
- func (c *Cache) Path() string
- func (c *Cache) PutDocument(accession string, doc *model.Document) error
- func (c *Cache) PutRaw(url string, body []byte) error
- type FetchFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultPath ¶
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 ¶
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 ¶
Clear truncates both layers, leaving an empty but valid cache. It is safe to call on a no-op cache.
func (*Cache) Fetching ¶
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 ¶
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 ¶
GetRaw returns the cached bytes for url and whether they were present. A no-op cache always misses.
func (*Cache) PutDocument ¶
PutDocument stores doc as canonical JSON keyed on accession, model.ParserVersion, and model.SchemaVersion. A no-op cache drops the write.