cache

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileCache

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

FileCache implements Service by storing schemas as JSON files on disk. Storage layout: {baseDir}/{domain}/{schemaID}.json

func NewFileCache

func NewFileCache(baseDir string, ttl time.Duration) *FileCache

NewFileCache creates a FileCache that stores schemas under baseDir and considers entries stale after ttl has elapsed since their CreatedAt.

func (*FileCache) Invalidate

func (fc *FileCache) Invalidate(_ context.Context, schemaID string) error

Invalidate removes {schemaID}.json from all domain directories. Returns nil if the schema file is not found.

func (*FileCache) Lookup

func (fc *FileCache) Lookup(ctx context.Context, targetURL string) (*schema.Schema, error)

Lookup returns the best matching cached schema. API schemas take priority over CSS selector schemas.

func (*FileCache) LookupAll

func (fc *FileCache) LookupAll(_ context.Context, targetURL string) (*schema.Schema, *schema.Schema, error)

LookupAll returns both the API schema and CSS schema for a URL, if they exist. API schema is always returned separately from CSS schema so the caller can implement priority logic.

func (*FileCache) Store

func (fc *FileCache) Store(_ context.Context, s *schema.Schema) error

Store writes a schema as indented JSON to {baseDir}/{domain}/{schemaID}.json, creating directories as needed.

func (*FileCache) StoreIfNoAPI

func (fc *FileCache) StoreIfNoAPI(ctx context.Context, s *schema.Schema) error

StoreIfNoAPI stores a CSS selector schema only if no API schema already exists for the same URL. Prevents CSS selectors from overwriting API schemas.

type Service

type Service interface {
	// Lookup finds the best matching cached schema for the given URL.
	// Returns nil, nil when no match is found.
	Lookup(ctx context.Context, targetURL string) (*schema.Schema, error)

	// LookupAll returns all matching cached schemas for the given URL,
	// separated by type. Returns (apiSchema, cssSchema, error).
	// Either may be nil if no schema of that type is cached.
	LookupAll(ctx context.Context, targetURL string) (apiSchema *schema.Schema, cssSchema *schema.Schema, err error)

	// Store persists a schema to the cache.
	Store(ctx context.Context, s *schema.Schema) error

	// StoreIfNoAPI stores a CSS selector schema only if no API schema
	// already exists for the same URL pattern. Prevents CSS from
	// overwriting a higher-quality API schema.
	StoreIfNoAPI(ctx context.Context, s *schema.Schema) error

	// Invalidate removes a cached schema by its ID.
	// Returns nil if the schema is not found.
	Invalidate(ctx context.Context, schemaID string) error
}

Service defines the contract for schema caching. Implementations store and retrieve discovered API schemas so that repeat fetches can skip LLM analysis.

Jump to

Keyboard shortcuts

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