api_cache

package module
v0.0.0-...-2afcc6f Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

README

api_cache

A URL cacher for slow API calls

Documentation

Overview

cacher provides disk caching of json retrieved from APIs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeCacheFileName

func MakeCacheFileName(urlStr string) (string, error)

MakeCacheFilename takes a URL and converts it into a string suitable for making meaningful cache filenames.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func NewCacher

func NewCacher(cacheDir string) *Cache

NewCacher creates and returns a new instance of Cache. It takes a directory name where cache files will be stored and will attempt to create that directory if it doesn't exist.

func (*Cache) AddURL

func (c *Cache) AddURL(itemKey, fileName string, validity int64)

AddURL registers a URL with a filename to contain its cached data. If the URL has no expiry associated with it, a new entry is created in the expiry cache and immediately set to expired.

func (*Cache) GetFilename

func (c *Cache) GetFilename(itemKey string) (string, error)

GetFilename returns the filename for a given cache item

func (*Cache) GetURL

func (c *Cache) GetURL(itemKey string) (gj gjson.Result, err error)

GetURL returns the file content associated with a cache key. If the cache has expired, the content will instead be grabbed from the API.

func (*Cache) HasExpired

func (c *Cache) HasExpired(itemKey string) (refresh bool, err error)

HasExpired takes a cache item and determines if it needs refreshing

func (*Cache) InitAPI

func (c *Cache) InitAPI(username, password, cert string)

InitAPI constructs a new instance of the Satellite API

func (*Cache) ResetExpire

func (c *Cache) ResetExpire(itemKey string) (err error)

ResetExpire resets the expiry field of a cache Item to current time + the defined validity period

func (*Cache) SetRefresh

func (c *Cache) SetRefresh()

SetRefresh instructs GetURL to ignore cached files and fetch (and cache) new copies.

func (*Cache) WriteExpiryFile

func (c *Cache) WriteExpiryFile() error

WriteExpiryFile writes the cache expiry map to a file in JSON format.

type Item

type Item struct {
	// contains filtered or unexported fields
}

Item contains variables relating to each item stored in the cache

Directories

Path Synopsis
satapi provides an API interface to Red Hat Satellite
satapi provides an API interface to Red Hat Satellite

Jump to

Keyboard shortcuts

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