referencecache

package
v0.0.0-...-469ea3f Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package referencecache holds small, slow-changing lookup data (ticket status/priority/prefix names, category tree) in memory so the tickets endpoints don't pay the JOIN cost on every request.

Refreshes are periodic, not write-driven. Callers tolerate cache miss as empty string / nil — never as error — because new addon-side records can land between refresh ticks.

Index

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
}

Cache is the canonical implementation.

func New

func New(loader Loader) *Cache

New returns an unpopulated cache. Callers must run Refresh once before serving traffic.

func (*Cache) Category

func (c *Cache) Category(id uint32) *CategoryRecord

func (*Cache) CategoryAncestors

func (c *Cache) CategoryAncestors(id uint32) []uint32

func (*Cache) CategoryTree

func (c *Cache) CategoryTree() []*CategoryRecord

func (*Cache) ExpandSubtree

func (c *Cache) ExpandSubtree(ids []uint32) []uint32

ExpandSubtree returns ids plus every descendant category id reachable through the cached tree. Unknown ids are passed through unchanged so the caller's SQL IN(...) clause behaves the same as if the cache were warm.

func (*Cache) PrefixName

func (c *Cache) PrefixName(id uint32) string

func (*Cache) PriorityName

func (c *Cache) PriorityName(id uint32) string

func (*Cache) Refresh

func (c *Cache) Refresh(ctx context.Context) error

func (*Cache) StatusName

func (c *Cache) StatusName(id uint32) string

type CategoryRecord

type CategoryRecord struct {
	ID           uint32
	Title        string
	Description  string
	ParentID     uint32
	Depth        uint32
	DisplayOrder uint32
	TicketCount  uint32
	Lft          uint32
	Rgt          uint32
}

CategoryRecord mirrors the row shape we care about from xf_nf_tickets_category. lft/rgt support subtree expansion.

type Loader

type Loader interface {
	LoadStatusNames(ctx context.Context) (map[uint32]string, error)
	LoadPriorityNames(ctx context.Context) (map[uint32]string, error)
	LoadPrefixNames(ctx context.Context) (map[uint32]string, error)
	LoadCategories(ctx context.Context) ([]*CategoryRecord, error)
}

Loader fetches data the cache holds. The cache implementation calls it at startup and on every refresh tick. Implementations live in the datastore package (against MariaDB).

type ReferenceCache

type ReferenceCache interface {
	StatusName(id uint32) string
	PriorityName(id uint32) string
	PrefixName(id uint32) string
	Category(id uint32) *CategoryRecord
	CategoryAncestors(id uint32) []uint32
	CategoryTree() []*CategoryRecord
	ExpandSubtree(ids []uint32) []uint32
	Refresh(ctx context.Context) error
}

ReferenceCache is what consumers (datastore methods, handlers) call.

Jump to

Keyboard shortcuts

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