cache

package
v0.0.13-beta Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cache returns a default cache manager with the `File` backend.

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

func File

func File(folder folder.Folder) file.File

File returns the cache file for the specified cache type.

Types

type Cache

type Cache struct {
	file.File
	// contains filtered or unexported fields
}

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

func New

func New(folder folder.Folder) *Cache

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

func (*Cache) Delete

func (c *Cache) Delete(id string) error

Delete removes an item from the cache by id.

func (*Cache) Get

func (c *Cache) Get(id string) (*Item, error)

Get retrieves an item from the cache by ID.

func (*Cache) GetAll

func (c *Cache) GetAll() ([]*Item, error)

GetAll retrieves all items from the cache.

func (*Cache) GetByProperty

func (c *Cache) GetByProperty(property, value string) (*Item, error)

GetByProperty retrieves an item from the cache by a specific property.

func (*Cache) Load

func (c *Cache) Load() error

Load creates or loads the cache file.

func (*Cache) Save

func (c *Cache) Save(item *Item) error

Save stores an item in the.

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 for the item.
	ID string
	// Name is the name of the item.
	Name string
	// Path is the path to the item.
	Path string
	// Version is the version of the item.
	Version string
	// Time is the time when the item was created or last updated.
	Downloaded time.Time
	// Updated is the time when the item was last updated.
	Updated time.Time
	// Type is the type of the item.
	Type string
}

Item represents a cache item.

type Items

type Items map[string]*Item

Items is a map of items indexed by their names.

Jump to

Keyboard shortcuts

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