cache

package
v4.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2017 License: AGPL-3.0, AGPL-3.0-or-later Imports: 5 Imported by: 0

Documentation

Overview

Package cache provides an in-memory LRU cache for reducing the duplicate workload of database requests and post HTML and JSON generation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Size sets the maximum size of cache before evicting unread data in MB
	Size float64 = 1 << 7
)

Functions

func Clear

func Clear()

Clear the cache. Only used for testing.

func GetHTML

func GetHTML(k Key, f FrontEnd) ([]byte, uint64, error)

GetHTML retrieves post HTML from the cache or generates fresh HTML as needed

func GetJSON

func GetJSON(k Key, f FrontEnd) ([]byte, uint64, error)

GetJSON retrieves JSON from the cache, validates it is still fresh or retrieves fresh data, if needed

Types

type FrontEnd

type FrontEnd struct {
	// GetCounter retrieves a new update counter for a resource
	GetCounter func(Key) (uint64, error)

	// GetFresh retrieves new post data from the database
	GetFresh func(Key) (easyjson.Marshaler, error)

	// RenderHTML produces HTML from the passed in data and JSON
	RenderHTML func(easyjson.Marshaler, []byte) []byte
}

FrontEnd provides functions for fetching, validating and generating the cache. GetCounter and GetFresh are mandatory, but you may omit RenderHTML, if you don't plan to call GetHTML with this FrontEnd.

type Key

type Key struct {
	LastN uint8
	Board string
	ID    uint64
}

Key stores the ID of either a thread or board page

func BoardKey

func BoardKey(b string, index bool) Key

BoardKey encodes a key for a board page resource

func ThreadKey

func ThreadKey(id uint64, lastN int) Key

ThreadKey encodes a Key from a thread's ID and last N posts to show setting

Jump to

Keyboard shortcuts

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