Documentation
¶
Index ¶
- type FileCache
- func (fc *FileCache) Invalidate(_ context.Context, schemaID string) error
- func (fc *FileCache) Lookup(ctx context.Context, targetURL string) (*schema.Schema, error)
- func (fc *FileCache) LookupAll(_ context.Context, targetURL string) (*schema.Schema, *schema.Schema, error)
- func (fc *FileCache) Store(_ context.Context, s *schema.Schema) error
- func (fc *FileCache) StoreIfNoAPI(ctx context.Context, s *schema.Schema) error
- type Service
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 ¶
NewFileCache creates a FileCache that stores schemas under baseDir and considers entries stale after ttl has elapsed since their CreatedAt.
func (*FileCache) Invalidate ¶
Invalidate removes {schemaID}.json from all domain directories. Returns nil if the schema file is not found.
func (*FileCache) Lookup ¶
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.
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.