cache

package
v1.2.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultMaxEntries = 500
	MaxAge            = 30 * 24 * time.Hour // 30 days
	CacheVersion      = "1.0"
)

Variables

This section is empty.

Functions

func GetDefaultCacheDir

func GetDefaultCacheDir() (string, error)

Types

type Cache

type Cache struct {
	Version       string       `json:"version"`
	LastSync      time.Time    `json:"last_sync"`
	Notifications []CacheEntry `json:"notifications"`
	Stars         []StarEvent  `json:"stars"`
	LastEventSync time.Time    `json:"last_event_sync"` // Track last sync for rate limiting
	MaxEntries    int          `json:"max_entries"`
}

Cache stores notifications and star events with their metadata.

IMPORTANT: All time.Time fields should use UTC to match GitHub API responses and ensure consistent time comparisons across different timezones. Use time.Now().UTC() when setting time fields to maintain consistency.

func New

func New(cacheDir string) *Cache

func (*Cache) AddNotifications

func (c *Cache) AddNotifications(notifications []CacheEntry) []CacheEntry

func (*Cache) AddStarEvents added in v1.1.0

func (c *Cache) AddStarEvents(starEvents []StarEvent) []StarEvent

AddStarEvents adds star events to the cache and returns only new ones

func (*Cache) Clear

func (c *Cache) Clear()

func (*Cache) GetNotifications

func (c *Cache) GetNotifications() []CacheEntry

func (*Cache) GetStars added in v1.1.0

func (c *Cache) GetStars() []StarEvent

GetStars returns a copy of cached star events

func (*Cache) Load

func (c *Cache) Load(cacheDir string) error

func (*Cache) Save

func (c *Cache) Save(cacheDir string) error

type CacheEntry

type CacheEntry struct {
	ID         string    `json:"id"`
	Repository string    `json:"repository"`
	Title      string    `json:"title"`
	Reason     string    `json:"reason"`
	Type       string    `json:"type"`
	URL        string    `json:"url"`
	WebURL     string    `json:"web_url"`
	Timestamp  time.Time `json:"timestamp"`
	UpdatedAt  time.Time `json:"updated_at"`
}

type StarEvent added in v1.1.0

type StarEvent struct {
	ID         string    `json:"id"`
	Repository string    `json:"repository"` // Full name: "owner/repo"
	StarredBy  string    `json:"starred_by"`
	StarredAt  time.Time `json:"starred_at"`
	Notified   bool      `json:"notified"`
}

StarEvent represents a star event for caching

Jump to

Keyboard shortcuts

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