cache

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key(absPath string) string

Key returns a cache key derived from the absolute path (first 16 hex chars of SHA256).

func ReadFile

func ReadFile(path string) (*format.Output, error)

ReadFile reads a raw JSON output file (not a cache wrapper).

Types

type Config

type Config struct {
	// Cache is where the cache files should go.
	Cache string `env:"INFRACOST_CLI_CACHE_DIRECTORY"`

	// TTL is how long cached results remain valid.
	TTL time.Duration `env:"INFRACOST_CLI_CACHE_TTL" default:"1h"`

	// SessionID identifies the current session (terminal, editor, CI job).
	// Falls back to the parent process ID if not set.
	SessionID string `env:"INFRACOST_SESSION_ID"`
}

func (*Config) Process added in v0.0.3

func (c *Config) Process()

func (*Config) Read

func (c *Config) Read(absPath string, allowChanged bool) (*Entry, error)

Read reads a cached entry for the given absolute path, returning an error if missing or expired.

allowChanged can be set to true to return the entry even if the files have changed (so the cache is stale). This is useful for tracking changes in the results between runs, but should be set to false when inspecting results to make sure results are up-to-date.

func (*Config) ReadLatest

func (c *Config) ReadLatest() (*Entry, error)

ReadLatest reads the most recently modified cache entry, returning an error if missing or expired.

func (*Config) Write

func (c *Config) Write(absPath string, data *format.Output) error

Write writes the output data to the cache for the given absolute path.

type Entry

type Entry struct {
	Version    int           `json:"version"`
	CreatedAt  time.Time     `json:"created_at"`
	SourcePath string        `json:"source_path"`
	SessionID  string        `json:"session_id,omitempty"`
	Data       format.Output `json:"data"`
}

func (*Entry) SameSession

func (e *Entry) SameSession(c *Config) bool

SameSession reports whether this entry was written by the same session as the current process (same terminal, editor, or CI job).

Jump to

Keyboard shortcuts

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