cacher

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

cacher provides disk caching of json retrieved from APIs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func NewCacher

func NewCacher(cacheDir string) *Cache

func (*Cache) AddURL

func (c *Cache) AddURL(item, fileName string)

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) GetFile added in v0.0.4

func (c *Cache) GetFile(item string) []byte

GetFile reads a cache item's file from disk and returns it as a byte slice.

func (*Cache) GetFilename added in v0.0.4

func (c *Cache) GetFilename(item string) (filename string)

GetFilename returns the filename for a given cache item

func (*Cache) GetURL

func (c *Cache) GetURL(item 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 added in v0.0.4

func (c *Cache) HasExpired(item 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) SetCacheDuration

func (c *Cache) SetCacheDuration(sec int64)

SetCacheDuration defines the expiry period in seconds for each cached file.

func (*Cache) SetRefresh

func (c *Cache) SetRefresh()

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

func (*Cache) UpdateExpiry added in v0.0.4

func (c *Cache) UpdateExpiry(item string, period int64) (newExpire int64)

UpdateExpiry revises the expiry time of a given cache item.

func (*Cache) WriteExpiryFile added in v0.0.4

func (c *Cache) WriteExpiryFile()

WriteExpiryFile writes the cache inventory to disk if writeExpiry is true. The writeExpiry boolean indicates that at least one cache item has been refreshed.

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