Documentation ¶
Overview ¶
cacher provides disk caching of json retrieved from APIs
Index ¶
- type Cache
- func (c *Cache) AddURL(item, fileName string)
- func (c *Cache) GetFile(item string) []byte
- func (c *Cache) GetFilename(item string) (filename string)
- func (c *Cache) GetURL(item string) (gj gjson.Result, err error)
- func (c *Cache) HasExpired(item string) (refresh bool, err error)
- func (c *Cache) InitAPI(username, password, cert string)
- func (c *Cache) SetCacheDuration(sec int64)
- func (c *Cache) SetRefresh()
- func (c *Cache) UpdateExpiry(item string, period int64) (newExpire int64)
- func (c *Cache) WriteExpiryFile()
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 (*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) GetFile ¶ added in v0.0.4
GetFile reads a cache item's file from disk and returns it as a byte slice.
func (*Cache) GetFilename ¶ added in v0.0.4
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 ¶ added in v0.0.4
HasExpired takes a cache item and determines if it needs refreshing
func (*Cache) SetCacheDuration ¶
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
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.