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 ¶
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 ¶
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) Update ¶
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 ¶
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.