Documentation ¶
Overview ¶
Package cache provides a cached interface to the xkcd server.
Index ¶
- Variables
- func CheckForNewestComicInfo(freshnessThreshold time.Duration) (*xkcd.Comic, error)
- func Close() error
- func ComicImagePath(n int) string
- func ComicInfo(n int) (*xkcd.Comic, error)
- func DownloadAllComicImages(cacheWindow ViewRefreshWitherGetter)
- func DownloadAllComicMetadata(cacheWindow ViewRefreshWitherGetter)
- func DownloadComicImage(n int, cacheWindow ViewRefresherGetter) error
- func Init(index func(comic *xkcd.Comic) error) error
- func NewestComicInfoFromCache() (*xkcd.Comic, error)
- type Stat
- type ViewRefreshWither
- type ViewRefreshWitherGetter
- type ViewRefresher
- type ViewRefresherGetter
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMiss means that value we are looking for wasn't in the cache. ErrMiss = errors.New("cache miss") // ErrLocalFailure means that there was an error while trying to access the // local cache. ErrLocalFailure = errors.New("error accessing local xkcd cache") // ErrOffline means that there was an error trying to access the xkcd // server. ErrOffline = errors.New("error accessing xkcd server") // ErrNoComicsFound is returned when a function can not find any comics. ErrNoComicsFound = errors.New("no comics found") )
Functions ¶
func CheckForNewestComicInfo ¶
CheckForNewestComicInfo returns the latest xkcd.Comic. May query xkcd API if latest comic in the cache has not been updated since freshnessThreshold. The returned error can be safely ignored. Should not be called directly in the UI event loop.
func ComicImagePath ¶
ComicImagePath returns the path to the specified comic image within the cache. The file at the returned path may or may not exist. If it does not exist, call DownloadComicImage to fetch the file from the internet.
func ComicInfo ¶
ComicInfo always returns a valid *xkcd.Comic that can be used, and err will be set if any errors were encountered, however these errors can be ignored safely.
func DownloadAllComicImages ¶ added in v1.7.0
func DownloadAllComicImages(cacheWindow ViewRefreshWitherGetter)
DownloadAllComicImages tries to add all comic images to our local cache. If successful, the images can be found at the path returned by ComicImagePath.
func DownloadAllComicMetadata ¶ added in v1.7.0
func DownloadAllComicMetadata(cacheWindow ViewRefreshWitherGetter)
DownloadAllComicMetadata asynchronously fills the comic metadata cache and search index via the internet. Status can be checked with Stat(). Should not be called directly in the UI event loop.
func DownloadComicImage ¶
func DownloadComicImage(n int, cacheWindow ViewRefresherGetter) error
DownloadComicImage tries to add a comic image to our local cache. If successful, the image can be found at the path returned by ComicImagePath.
func Init ¶
Init initializes the comic cache. Function index is called each time a comic is inserted into the comic cache.
func NewestComicInfoFromCache ¶
NewestComicInfoFromCache returns the newest comic info available in the cache. The function will not use the internet. The returned error can be safely ignored. Can be used on UI event loop.
Types ¶
type ViewRefreshWither ¶ added in v1.7.0
ViewRefreshWither provides methods for refreshing a view of cache statistics with the provided stat. All methods must silently accept a nil receiver.
type ViewRefreshWitherGetter ¶ added in v1.7.0
type ViewRefreshWitherGetter func() ViewRefreshWither
ViewRefreshWitherGetter returns a ViewRefreshWither. Useful for lazily passing the ViewRefreshWither as an argument.
type ViewRefresher ¶ added in v1.7.0
type ViewRefresher interface { ViewRefreshWither // RefreshMetadata queries StatMetadata then calls RefreshMetadataWith. RefreshMetadata() // RefreshImages queries StatImages then calls RefreshImagesWith. RefreshImages() }
ViewRefresher provides methods for refreshing a view of cache statistics. All methods must silently accept a nil receiver.
type ViewRefresherGetter ¶ added in v1.7.0
type ViewRefresherGetter func() ViewRefresher
ViewRefresherGetter returns a ViewRefresher. Useful for lazily passing the ViewRefresher as an argument.