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 ¶
- type Cache
- func (c *Cache) Category(id uint32) *CategoryRecord
- func (c *Cache) CategoryAncestors(id uint32) []uint32
- func (c *Cache) CategoryTree() []*CategoryRecord
- func (c *Cache) ExpandSubtree(ids []uint32) []uint32
- func (c *Cache) PrefixName(id uint32) string
- func (c *Cache) PriorityName(id uint32) string
- func (c *Cache) Refresh(ctx context.Context) error
- func (c *Cache) StatusName(id uint32) string
- type CategoryRecord
- type Loader
- type ReferenceCache
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 (*Cache) Category ¶
func (c *Cache) Category(id uint32) *CategoryRecord
func (*Cache) CategoryAncestors ¶
func (*Cache) CategoryTree ¶
func (c *Cache) CategoryTree() []*CategoryRecord
func (*Cache) ExpandSubtree ¶
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 (*Cache) PriorityName ¶
func (*Cache) StatusName ¶
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.