cache

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBPath

func DBPath() (string, error)

DBPath returns the default cache database path.

Types

type BBoltStore

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

BBoltStore implements Store using an embedded bbolt database.

func NewBBoltStore

func NewBBoltStore(path string) (*BBoltStore, error)

NewBBoltStore opens or creates a bbolt database at the given path.

func NewBBoltStoreReadOnly

func NewBBoltStoreReadOnly(path string) (*BBoltStore, error)

NewBBoltStoreReadOnly opens a bbolt database for reading. Use when another process may hold the write lock.

func (*BBoltStore) Clear

func (s *BBoltStore) Clear() error

func (*BBoltStore) Close

func (s *BBoltStore) Close() error

func (*BBoltStore) Get

func (s *BBoltStore) Get(key string) ([]byte, error)

func (*BBoltStore) Put

func (s *BBoltStore) Put(key string, value []byte) error

func (*BBoltStore) Stats

func (s *BBoltStore) Stats() (entries int, sizeBytes int64)

type Cache

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

Cache provides TTL-based page caching backed by a Store.

func New

func New(ttl time.Duration) *Cache

New creates a cache with the default bbolt backend. Returns nil if the cache cannot be initialized.

func NewFromConfig

func NewFromConfig(cfg *config.Config) *Cache

NewFromConfig creates a cache with the TTL parsed from cfg.CacheTTL, falling back to one hour if the value doesn't parse. Returns nil (a valid, no-op cache — all methods are nil-safe) if the cache cannot be initialized.

func NewReadOnly

func NewReadOnly() *Cache

NewReadOnly opens the cache for reading only. Use for stats/inspection when another process may hold the write lock.

func NewWithStore

func NewWithStore(store Store, ttl time.Duration) *Cache

NewWithStore builds a cache over a caller-supplied Store. Used by tests to isolate the cache (temp bbolt path) from the user's real cache dir.

func (*Cache) Clear

func (c *Cache) Clear() error

Clear removes all cached pages.

func (*Cache) Close

func (c *Cache) Close()

Close releases cache resources.

func (*Cache) Get

func (c *Cache) Get(url string) (*scrape.Page, string)

Get looks up a cached page by URL. Returns (nil, "") if missing or expired. The second return is the fetch source recorded at Put time (scrape.SourceHTTP or scrape.SourceBrowser); empty for entries written before source tracking.

func (*Cache) GetRaw

func (c *Cache) GetRaw(url string) (string, string, *scrape.Page)

GetRaw looks up a cached entry's raw HTML by URL. Returns (rawHTML, source, page). It is a hit only when the entry exists, is fresh, AND has non-empty RawHTML — a markdown-only entry must not poison a --raw request (serving empty HTML). On miss or empty raw, returns ("", "", nil) so the caller refetches and back-fills.

func (*Cache) Put

func (c *Cache) Put(url string, page *scrape.Page, source string)

Put writes a page to the cache with the fetch source that produced it.

func (*Cache) PutRaw

func (c *Cache) PutRaw(url string, page *scrape.Page, source, rawHTML string)

PutRaw writes a page plus its raw HTML to the cache with the fetch source. Used by --raw to persist both representations from a single fetch. The markdown-only Put path is unchanged and keeps omitting RawHTML.

func (*Cache) Stats

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

Stats returns cache entry count and total size in bytes.

type Store

type Store interface {
	Get(key string) ([]byte, error)
	Put(key string, value []byte) error
	Stats() (entries int, sizeBytes int64)
	Clear() error
	Close() error
}

Store is the interface for cache storage backends. Default is bbolt; future backends (redis, etc.) implement this.

Jump to

Keyboard shortcuts

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