cache

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package cache implements in memory cache for the index files. At creation time, a cache object loads in memory the index files if any is found on disk. Otherwise, it starts blank. A cache object allow to add, remove, update index files. If necessary it allows to persist the cache to disk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	*index.MergedIndexes
	// contains filtered or unexported fields
}

Cache manages the index files.

func New

func New(ctx context.Context, indexFile, indexesDir string) (*Cache, error)

New creates a new cache object. For each entry in the indexes.yaml file it loads the respective index file found on the disk or fetches it if not found. If there is an entry in the indexes.yaml file but its index file does not exist on the disk then it will error.

func NewFromConfig

func NewFromConfig(ctx context.Context, indexFile, indexesDir string, indexes []config.Index) (*Cache, error)

NewFromConfig creates a new cache object from a set of indexes. The new cache fetches the indexes only if they do not exist in the filesystem. The local indexes info is ignored, it takes into account the indexes passed as arguments.

func (*Cache) Add

func (c *Cache) Add(ctx context.Context, name, backend, url string) error

Add adds a new index file to the cache. If the index file already exists in the cache it does nothing. On the other hand, it fetches the index file using the provided URL and adds it to the in memory cache. It does not write it to the filesystem. It is idempotent.

func (*Cache) Remove

func (c *Cache) Remove(name string) error

Remove removes an index file from the cache if it exists.

func (*Cache) Update

func (c *Cache) Update(ctx context.Context, name string) error

Update updates an index entry by fetching the new content from the configured URL for the given index. The new content is kept in memory, it does not overwrite the existing index file on the disk.

func (*Cache) Write

func (c *Cache) Write() (*indexConf.Config, error)

Write dumps the in-memory cache to disk. Based on the cache operations it does different things. Add: a new entry is added to the config.IndexesFile and the fetched index file is saved under the config.IndexesDir. Remove: the removed entry is wiped out from the config.IndexesFile and the related index file is deleted. Update: the entry in the config.IndexesFile for the updated index is updated. The related index file is replaced by the new content fetched by the update operation. Returns the indexConf.Config written to the config.IndexesFile.

Jump to

Keyboard shortcuts

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