cache

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheDir     = ".abscleaner"
	CacheFile    = "cache.json"
	CacheVersion = "1.0"
)

Variables

This section is empty.

Functions

func CalculateFileHash

func CalculateFileHash(filePath string) (string, error)

CalculateFileHash calculates SHA256 hash of a file using streaming for better memory efficiency

Types

type CacheData

type CacheData struct {
	Version      string        `json:"version"`
	Files        []*FileRecord `json:"files"`
	IgnoredRules []IgnoredRule `json:"ignored_rules"`
	Stats        *CacheStats   `json:"stats"`
	LastUpdated  time.Time     `json:"last_updated"`
}

type CacheStats

type CacheStats struct {
	TotalFiles    int       `json:"total_files"`
	TotalIssues   int       `json:"total_issues"`
	IgnoredIssues int       `json:"ignored_issues"`
	FixedIssues   int       `json:"fixed_issues"`
	LastFullScan  time.Time `json:"last_full_scan"`
	CacheHits     int       `json:"cache_hits"`
	CacheMisses   int       `json:"cache_misses"`
}

type Entry

type Entry struct {
	Hash   string          `json:"hash"`
	Issues []*models.Issue `json:"issues"`
}

Entry represents a cache entry (used by HybridCache)

type FileCache

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

func New

func New(baseDir string) (*FileCache, error)

New creates a new file-based cache

func (*FileCache) AddIgnoredRule

func (fc *FileCache) AddIgnoredRule(filePattern, ruleType string) error

AddIgnoredRule adds a rule type to ignore for a file pattern

func (*FileCache) ClearCache

func (fc *FileCache) ClearCache() error

ClearCache clears all cached data

func (*FileCache) Close

func (fc *FileCache) Close() error

Close saves and closes the cache (satisfies DB interface)

func (*FileCache) GetCacheDir

func (fc *FileCache) GetCacheDir() string

GetCacheDir returns the cache directory path

func (*FileCache) GetFileRecord

func (fc *FileCache) GetFileRecord(filePath string) (*FileRecord, error)

GetFileRecord retrieves a file record

func (*FileCache) GetStats

func (fc *FileCache) GetStats() map[string]interface{}

GetStats returns cache statistics

func (*FileCache) IgnoreIssue

func (fc *FileCache) IgnoreIssue(filePath, issueID, ignoreType string) error

IgnoreIssue marks an issue as ignored

func (*FileCache) IsFileChanged

func (fc *FileCache) IsFileChanged(filePath string) (bool, error)

IsFileChanged checks if a file has changed since last analysis

func (*FileCache) IsIssueIgnored

func (fc *FileCache) IsIssueIgnored(filePath, issueID string) (bool, error)

IsIssueIgnored checks if an issue is ignored

func (*FileCache) MarkIssueFixed

func (fc *FileCache) MarkIssueFixed(filePath, issueID string) error

MarkIssueFixed marks an issue as fixed

func (*FileCache) SaveFileRecord

func (fc *FileCache) SaveFileRecord(filePath string, issues []interface{}) error

SaveFileRecord saves or updates a file record

func (*FileCache) SaveRawRecord

func (fc *FileCache) SaveRawRecord(key string, entry Entry) error

SaveRawRecord saves a raw Entry directly

func (*FileCache) ShouldIgnoreRule

func (fc *FileCache) ShouldIgnoreRule(filePath, ruleType string) bool

ShouldIgnoreRule checks if a rule should be ignored for a file

type FileRecord

type FileRecord struct {
	Path         string          `json:"path"`
	Hash         string          `json:"hash"`
	LastAnalyzed time.Time       `json:"last_analyzed"`
	Issues       []*models.Issue `json:"issues"`
	Ignored      []string        `json:"ignored"` // Issue IDs that are ignored
}

type HybridCache

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

HybridCache combines in-memory LRU cache with disk persistence

func NewHybridCache

func NewHybridCache(baseDir string, maxItems int) (*HybridCache, error)

NewHybridCache creates a new hybrid cache with LRU eviction

func (*HybridCache) Clear

func (hc *HybridCache) Clear() error

Clear clears both memory and disk cache

func (*HybridCache) Close

func (hc *HybridCache) Close() error

Close flushes and closes the cache

func (*HybridCache) Flush

func (hc *HybridCache) Flush() error

Flush writes all dirty items to disk

func (*HybridCache) Get

func (hc *HybridCache) Get(key string) (*Entry, bool)

Get retrieves an item from cache (memory first, then disk)

func (*HybridCache) Put

func (hc *HybridCache) Put(key string, entry Entry)

Put adds or updates an item in the cache

func (*HybridCache) Stats

func (hc *HybridCache) Stats() map[string]interface{}

Stats return cache statistics

type IgnoredRule

type IgnoredRule struct {
	FilePattern string   `json:"file_pattern"`
	RuleTypes   []string `json:"rule_types"`
}

Jump to

Keyboard shortcuts

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