cache

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package cache handles the caching of the downloaded items.

Index

Constants

This section is empty.

Variables

View Source
var ErrItemNotFound = errors.New("item not found")

ErrItemNotFound is returned when an item is not found in the cache.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	file.File // embedded file.File for cache operations
	// contains filtered or unexported fields
}

Cache is a cache backend that stores data in a JSON file.

func New

func New(file file.File) *Cache

New creates a new cache manager with the specified file as the backend.

func (*Cache) Add added in v0.0.13

func (c *Cache) Add(items ...*Item) error

Add stores items in the cache.

func (*Cache) Delete

func (c *Cache) Delete(identifiers ...string) error

Delete removes items from the cache by identifier. If no identifiers are provided, it deletes all items in the cache.

func (*Cache) DeleteByName added in v0.0.13

func (c *Cache) DeleteByName(names ...string) error

DeleteByName removes items from the cache by name. If no names are provided, it deletes all items in the cache.

func (*Cache) Get

func (c *Cache) Get(identifiers ...string) ([]*Item, error)

Get retrieves items from the cache by ID. If no identifiers are provided, it returns all items in the cache.

func (*Cache) GetByName added in v0.0.13

func (c *Cache) GetByName(names ...string) ([]*Item, error)

GetByName retrieves items from the cache by name.

func (*Cache) IsEmpty added in v0.0.13

func (c *Cache) IsEmpty() bool

IsEmpty checks if the cache is empty.

func (*Cache) Load

func (c *Cache) Load() error

Load creates or loads the cache file.

func (*Cache) Touched

func (c *Cache) Touched() bool

Touched returns true if the cache was modified.

type Item

type Item struct {
	// ID is the unique identifier of the item.
	ID string `json:"id"`

	// Name is the name of the item.
	Name string `json:"name"`

	// Path is the file path of the item.
	Path string `json:"path"`

	// Type is the type of the item.
	Type string `json:"type"`

	// Version of the item.
	Version version.Version `json:"version"`

	// Downloaded is the time when the item was downloaded.
	Downloaded time.Time `json:"downloaded"`

	// Updated is the time when the item was last updated.
	Updated time.Time `json:"updated"`
}

Item represents a cache item.

type Items

type Items map[string]*Item

Items is a map of items indexed by their names.

func (Items) AsSlice added in v0.0.13

func (i Items) AsSlice() []*Item

AsSlice converts the Items map to a slice of pointers to Item.

Jump to

Keyboard shortcuts

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