Documentation ¶
Overview ¶
Package cache provides an interface for a cache of strings, aka text/gemini pages, and redirects. It is fully thread safe.
Index ¶
- func AddPage(p *structs.Page)
- func AddRedir(og, redir string)
- func ClearPages()
- func ClearRedirs()
- func GetPage(url string) (*structs.Page, bool)
- func NumPages() int
- func NumRedirs() int
- func Redirect(u string) string
- func RemovePage(url string)
- func SetMaxPages(max int)
- func SetMaxSize(max int)
- func SetTimeout(t int)
- func SizePages() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddPage ¶
AddPage adds a page to the cache, removing earlier pages as needed to keep the cache inside its limits.
If your page is larger than the max cache size, the provided page will silently not be added to the cache.
func AddRedir ¶
func AddRedir(og, redir string)
AddRedir adds a original-to-redirect pair to the cache.
func GetPage ¶
GetPage returns the page struct, and a bool indicating if the page was in the cache or not. (nil, false) is returned if the page isn't in the cache.
func Redirect ¶
Redirect takes the provided URL and returns a redirected version, if a redirect exists for that URL in the cache. If one does not then the original URL is returned.
func RemovePage ¶
func RemovePage(url string)
RemovePage will remove a page from the cache. Even if the page doesn't exist there will be no error.
func SetMaxPages ¶
func SetMaxPages(max int)
SetMaxPages sets the max number of pages the cache can hold. A value <= 0 means infinite pages.
func SetMaxSize ¶
func SetMaxSize(max int)
SetMaxSize sets the max size the page cache can be, in bytes. A value <= 0 means infinite size.
func SetTimeout ¶
func SetTimeout(t int)
SetTimeout sets the max number of a seconds a page can still be valid for. A value <= 0 means forever.
Types ¶
This section is empty.