Documentation
¶
Overview ¶
cacher provides disk caching of json retrieved from APIs
Index ¶
- func MakeCacheFileName(urlStr string) (string, error)
- type Cache
- func (c *Cache) AddURL(itemKey, fileName string, validity int64)
- func (c *Cache) GetFilename(itemKey string) (string, error)
- func (c *Cache) GetURL(itemKey string) (gj gjson.Result, err error)
- func (c *Cache) HasExpired(itemKey string) (refresh bool, err error)
- func (c *Cache) InitAPI(username, password, cert string)
- func (c *Cache) ResetExpire(itemKey string) (err error)
- func (c *Cache) SetRefresh()
- func (c *Cache) WriteExpiryFile() error
- type Item
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeCacheFileName ¶
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 ¶
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 ¶
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 ¶
GetFilename returns the filename for a given cache item
func (*Cache) GetURL ¶
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 ¶
HasExpired takes a cache item and determines if it needs refreshing
func (*Cache) ResetExpire ¶
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 ¶
WriteExpiryFile writes the cache expiry map to a file in JSON format.