cache

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cache provides caching functionality for gemtracker analysis results.

Analysis results are cached based on Gemfile.lock modification time. When a Gemfile.lock is analyzed, the results are stored in ~/.cache/gemtracker/ with a filename derived from the file path hash. On subsequent runs, the cache is checked for validity by comparing the cached modification time with the current file modification time.

Health cache handling is included in the cache package. See the cache package documentation for overall caching strategy.

Index

Constants

View Source
const HealthCacheTTL = 12 * 24 * time.Hour

HealthCacheTTL is the time-to-live for cached health data (12 days). Health metrics (last release, maintainer count, activity) change on a yearly timescale, so this conservative value drastically reduces API calls while remaining accurate.

Variables

This section is empty.

Functions

func Clear

func Clear(gemfileLockPath string) error

Clear removes the cache entry for a given Gemfile.lock. Returns an error if the cache file cannot be deleted.

func ClearHealth added in v1.1.2

func ClearHealth(gemfileLockPath string) error

ClearHealth removes the health cache entry for a given Gemfile.lock. Returns an error if the cache file cannot be deleted.

func GetCacheDir

func GetCacheDir() (string, error)

GetCacheDir returns the cache directory path (~/.cache/gemtracker), creating it if needed. Returns an error if the home directory cannot be determined or the directory cannot be created.

func GetCachePath

func GetCachePath(gemfileLockPath string) (string, error)

GetCachePath returns the cache file path for a given Gemfile.lock. The filename is derived from a hash of the absolute path to ensure uniqueness across projects.

func Write

func Write(gemfileLockPath string, entry *CacheEntry) error

Write writes an analysis result to cache, recording the Gemfile.lock modification time and current timestamp. Returns an error if the cache file cannot be written.

func WriteHealth added in v1.1.0

func WriteHealth(gemfileLockPath string, entry *HealthCacheEntry) error

WriteHealth writes gem health data to cache with the current timestamp. Returns an error if the cache file cannot be written.

Types

type CacheEntry

type CacheEntry struct {
	Result            *gemfile.AnalysisResult `json:"result"`
	GemfileLockMtime  int64                   `json:"gemfile_lock_mtime"`
	CachedAt          time.Time               `json:"cached_at"`
	RubyVersion       string                  `json:"ruby_version"`
	BundleVersion     string                  `json:"bundle_version"`
	FrameworkDetected string                  `json:"framework_detected"`
	RailsVersion      string                  `json:"rails_version"`
}

CacheEntry represents a cached analysis result with metadata about the Gemfile.lock that was analyzed and project information (Ruby version, bundle version, framework).

func Read

func Read(gemfileLockPath string) (*CacheEntry, error)

Read reads and returns a cached analysis result if it exists and is still valid. Returns nil if the cache file doesn't exist or the Gemfile.lock has been modified since caching. Returns an error if the cache file cannot be read or parsed.

type HealthCacheEntry added in v1.1.0

type HealthCacheEntry struct {
	Gems     map[string]*gemfile.GemHealth `json:"gems"`
	CachedAt time.Time                     `json:"cached_at"`
}

HealthCacheEntry stores cached gem health metrics for a Gemfile.lock with a 12-day time-to-live. It maps gem names to their cached health data including maintenance status and metrics.

func ReadHealth added in v1.1.0

func ReadHealth(gemfileLockPath string) (*HealthCacheEntry, error)

ReadHealth reads and returns the cached gem health data for a Gemfile.lock if it exists and is still valid (less than HealthCacheTTL old). Returns nil if the cache file doesn't exist or has expired. Returns an error if the cache file cannot be read or parsed.

Jump to

Keyboard shortcuts

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