cache

package
v0.0.0-...-e184c4b Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cache provides an interface for a cache of strings, aka text/gemini pages, and redirects. It is fully thread safe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPage

func AddPage(p *structs.Page)

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 ClearPages

func ClearPages()

ClearPages removes all pages from the cache.

func ClearRedirs

func ClearRedirs()

ClearRedirs removes all redirects from the cache.

func GetPage

func GetPage(url string) (*structs.Page, bool)

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 NumPages

func NumPages() int

func NumRedirs

func NumRedirs() int

func Redirect

func Redirect(u string) string

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.

func SizePages

func SizePages() int

SizePages returns the approx. current size of the cache in bytes.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL