cache

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package cache provides incremental build caching for OpenAPI spec generation. It stores parsed results in .openapi/ directory to speed up subsequent builds.

Index

Constants

View Source
const (
	// CacheDir is the directory where cache files are stored
	CacheDir = ".openapi"
	// IndexFile is the cache index file name
	IndexFile = "index.json"
	// SchemasDir stores cached schema definitions
	SchemasDir = "schemas"
	// RoutesDir stores cached route definitions
	RoutesDir = "routes"
)

Variables

This section is empty.

Functions

func CalculateChecksum

func CalculateChecksum(filePath string) (string, error)

CalculateChecksum calculates SHA256 checksum of a file.

func CalculateContentChecksum

func CalculateContentChecksum(content []byte) string

CalculateContentChecksum calculates SHA256 checksum of content bytes.

Types

type CacheStats

type CacheStats struct {
	FileCount      int
	SchemaCount    int
	RouteCount     int
	ParameterCount int
}

CacheStats holds statistics about the cache.

type FileEntry

type FileEntry struct {
	// Checksum is the SHA256 hash of the source file
	Checksum string `json:"checksum"`
	// ParsedAt is when the file was last parsed
	ParsedAt time.Time `json:"parsedAt"`
	// Schemas exported by this file (schema names)
	Schemas []string `json:"schemas,omitempty"`
	// Routes exported by this file (operation IDs)
	Routes []string `json:"routes,omitempty"`
	// Parameters exported by this file
	Parameters []string `json:"parameters,omitempty"`
}

FileEntry represents a cached entry for a single source file.

type Index

type Index struct {
	// Version of the cache format
	Version string `json:"version"`
	// CreatedAt is when the cache was first created
	CreatedAt time.Time `json:"createdAt"`
	// UpdatedAt is when the cache was last updated
	UpdatedAt time.Time `json:"updatedAt"`
	// Files maps source file paths to their cache entries
	Files map[string]*FileEntry `json:"files"`
}

Index represents the cache index that tracks all cached files.

func NewIndex

func NewIndex() *Index

NewIndex creates a new empty cache index.

func (*Index) GetEntry

func (idx *Index) GetEntry(relPath string) (*FileEntry, bool)

GetEntry returns the cache entry for a file.

func (*Index) Load

func (idx *Index) Load(path string) error

Load reads the index from disk.

func (*Index) NeedsUpdate

func (idx *Index) NeedsUpdate(relPath, checksum string) bool

NeedsUpdate checks if a source file needs to be re-parsed.

func (*Index) RemoveEntry

func (idx *Index) RemoveEntry(relPath string)

RemoveEntry removes a cache entry.

func (*Index) Save

func (idx *Index) Save(path string) error

Save writes the index to disk.

func (*Index) SetEntry

func (idx *Index) SetEntry(relPath string, entry *FileEntry)

SetEntry updates or creates a cache entry for a file.

type Manager

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

Manager handles all cache operations.

func NewManager

func NewManager(baseDir string) *Manager

NewManager creates a new cache manager for the given base directory.

func (*Manager) CachePath

func (m *Manager) CachePath() string

CachePath returns the full path to the cache directory.

func (*Manager) Clean

func (m *Manager) Clean() error

Clean removes all cache files.

func (*Manager) DeleteRoute

func (m *Manager) DeleteRoute(operationID string) error

DeleteRoute removes a route from cache.

func (*Manager) DeleteSchema

func (m *Manager) DeleteSchema(name string) error

DeleteSchema removes a schema from cache.

func (*Manager) GetEntry

func (m *Manager) GetEntry(filePath string) (*FileEntry, bool)

GetEntry returns the cache entry for a file.

func (*Manager) IndexPath

func (m *Manager) IndexPath() string

IndexPath returns the full path to the index file.

func (*Manager) Init

func (m *Manager) Init() error

Init initializes the cache directory structure.

func (*Manager) Load

func (m *Manager) Load() error

Load reads the cache index from disk.

func (*Manager) LoadAllRoutes

func (m *Manager) LoadAllRoutes() (map[string]*spec.Operation, error)

LoadAllRoutes loads all cached routes.

func (*Manager) LoadAllSchemas

func (m *Manager) LoadAllSchemas() (map[string]*spec.Schema, error)

LoadAllSchemas loads all cached schemas.

func (*Manager) LoadRoute

func (m *Manager) LoadRoute(operationID string) (*spec.Operation, error)

LoadRoute loads a route/operation from the cache.

func (*Manager) LoadSchema

func (m *Manager) LoadSchema(name string) (*spec.Schema, error)

LoadSchema loads a schema from the cache.

func (*Manager) NeedsUpdate

func (m *Manager) NeedsUpdate(filePath string) (bool, error)

NeedsUpdate checks if a source file needs to be re-parsed.

func (*Manager) Save

func (m *Manager) Save() error

Save writes the cache index to disk.

func (*Manager) SaveRoute

func (m *Manager) SaveRoute(operationID string, operation *spec.Operation) error

SaveRoute saves a route/operation to the cache.

func (*Manager) SaveSchema

func (m *Manager) SaveSchema(name string, schema *spec.Schema) error

SaveSchema saves a schema to the cache. The schema is stored as JSON with unresolved $refs.

func (*Manager) Stats

func (m *Manager) Stats() CacheStats

Stats returns statistics about the current cache state.

func (*Manager) UpdateEntry

func (m *Manager) UpdateEntry(filePath string, schemas, routes, parameters []string) error

UpdateEntry updates the cache entry for a source file. filePath can be either absolute or relative to baseDir.

Jump to

Keyboard shortcuts

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