cache

package
v0.14.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Possible cache visibility lookup types.
	VisibilityTypeAccount = VisibilityType('a')
	VisibilityTypeStatus  = VisibilityType('s')
	VisibilityTypeHome    = VisibilityType('h')
	VisibilityTypePublic  = VisibilityType('p')
)

Variables

View Source
var SentinelError = errors.New("BUG: error should not be returned") //nolint:revive

SentinelError is an error that can be returned and checked against to indicate a non-permanent error return from a cache loader callback, e.g. a temporary situation that will soon be fixed.

Functions

This section is empty.

Types

type CachedVisibility added in v0.8.0

type CachedVisibility struct {
	// ItemID is the ID of the item in question (status / account).
	ItemID string

	// RequesterID is the ID of the requesting account for this visibility lookup.
	RequesterID string

	// Type is the visibility lookup type.
	Type VisibilityType

	// Value is the actual visibility value.
	Value bool
}

CachedVisibility represents a cached visibility lookup value.

type Caches added in v0.7.0

type Caches struct {
	// GTS provides access to the collection of
	// gtsmodel object caches. (used by the database).
	GTS GTSCaches

	// AllowHeaderFilters provides access to
	// the allow []headerfilter.Filter cache.
	AllowHeaderFilters headerfilter.Cache

	// BlockHeaderFilters provides access to
	// the block []headerfilter.Filter cache.
	BlockHeaderFilters headerfilter.Cache

	// Visibility provides access to the item visibility
	// cache. (used by the visibility filter).
	Visibility VisibilityCache
	// contains filtered or unexported fields
}

func (*Caches) Init added in v0.7.0

func (c *Caches) Init()

Init will (re)initialize both the GTS and AP cache collections. NOTE: the cache MUST NOT be in use anywhere, this is not thread-safe.

func (*Caches) OnInvalidateAccount added in v0.14.0

func (c *Caches) OnInvalidateAccount(account *gtsmodel.Account)

func (*Caches) OnInvalidateBlock added in v0.14.0

func (c *Caches) OnInvalidateBlock(block *gtsmodel.Block)

func (*Caches) OnInvalidateEmojiCategory added in v0.14.0

func (c *Caches) OnInvalidateEmojiCategory(category *gtsmodel.EmojiCategory)

func (*Caches) OnInvalidateFollow added in v0.14.0

func (c *Caches) OnInvalidateFollow(follow *gtsmodel.Follow)

func (*Caches) OnInvalidateFollowRequest added in v0.14.0

func (c *Caches) OnInvalidateFollowRequest(followReq *gtsmodel.FollowRequest)

func (*Caches) OnInvalidateList added in v0.14.0

func (c *Caches) OnInvalidateList(list *gtsmodel.List)

func (*Caches) OnInvalidateMedia added in v0.14.0

func (c *Caches) OnInvalidateMedia(media *gtsmodel.MediaAttachment)

func (*Caches) OnInvalidatePoll added in v0.14.0

func (c *Caches) OnInvalidatePoll(poll *gtsmodel.Poll)

func (*Caches) OnInvalidatePollVote added in v0.14.0

func (c *Caches) OnInvalidatePollVote(vote *gtsmodel.PollVote)

func (*Caches) OnInvalidateStatus added in v0.14.0

func (c *Caches) OnInvalidateStatus(status *gtsmodel.Status)

func (*Caches) OnInvalidateStatusFave added in v0.14.0

func (c *Caches) OnInvalidateStatusFave(fave *gtsmodel.StatusFave)

func (*Caches) OnInvalidateUser added in v0.14.0

func (c *Caches) OnInvalidateUser(user *gtsmodel.User)

func (*Caches) Start added in v0.7.0

func (c *Caches) Start()

Start will start any caches that require a background routine, which usually means any kind of TTL caches.

func (*Caches) Stop added in v0.7.0

func (c *Caches) Stop()

Stop will stop any caches that require a background routine, which usually means any kind of TTL caches.

func (*Caches) Sweep added in v0.11.0

func (c *Caches) Sweep(threshold float64)

Sweep will sweep all the available caches to ensure none are above threshold percent full to their total capacity.

This helps with cache performance, as a full cache will require an eviction on every single write, which adds significant overhead to all cache writes.

type GTSCaches added in v0.7.0

type GTSCaches struct {
	// Account provides access to the gtsmodel Account database cache.
	Account structr.Cache[*gtsmodel.Account]

	// AccountNote provides access to the gtsmodel Note database cache.
	AccountNote structr.Cache[*gtsmodel.AccountNote]

	// TEMPORARY CACHE TO ALLEVIATE SLOW COUNT QUERIES,
	// (in time will be removed when these IDs are cached).
	AccountCounts *simple.Cache[string, struct {
		Statuses int
		Pinned   int
	}]

	// Application provides access to the gtsmodel Application database cache.
	Application structr.Cache[*gtsmodel.Application]

	// Block provides access to the gtsmodel Block (account) database cache.
	Block structr.Cache[*gtsmodel.Block]

	// FollowIDs provides access to the block IDs database cache.
	BlockIDs *SliceCache[string]

	// BoostOfIDs provides access to the boost of IDs list database cache.
	BoostOfIDs *SliceCache[string]

	// DomainAllow provides access to the domain allow database cache.
	DomainAllow *domain.Cache

	// DomainBlock provides access to the domain block database cache.
	DomainBlock *domain.Cache

	// Emoji provides access to the gtsmodel Emoji database cache.
	Emoji structr.Cache[*gtsmodel.Emoji]

	// EmojiCategory provides access to the gtsmodel EmojiCategory database cache.
	EmojiCategory structr.Cache[*gtsmodel.EmojiCategory]

	// Follow provides access to the gtsmodel Follow database cache.
	Follow structr.Cache[*gtsmodel.Follow]

	// FollowIDs provides access to the follower / following IDs database cache.
	// THIS CACHE IS KEYED AS THE FOLLOWING {prefix}{accountID} WHERE PREFIX IS:
	// - '>'  for following IDs
	// - 'l>' for local following IDs
	// - '<'  for follower IDs
	// - 'l<' for local follower IDs
	FollowIDs *SliceCache[string]

	// FollowRequest provides access to the gtsmodel FollowRequest database cache.
	FollowRequest structr.Cache[*gtsmodel.FollowRequest]

	// FollowRequestIDs provides access to the follow requester / requesting IDs database
	// cache. THIS CACHE IS KEYED AS THE FOLLOWING {prefix}{accountID} WHERE PREFIX IS:
	// - '>'  for following IDs
	// - '<'  for follower IDs
	FollowRequestIDs *SliceCache[string]

	// Instance provides access to the gtsmodel Instance database cache.
	Instance structr.Cache[*gtsmodel.Instance]

	// InReplyToIDs provides access to the status in reply to IDs list database cache.
	InReplyToIDs *SliceCache[string]

	// List provides access to the gtsmodel List database cache.
	List structr.Cache[*gtsmodel.List]

	// ListEntry provides access to the gtsmodel ListEntry database cache.
	ListEntry structr.Cache[*gtsmodel.ListEntry]

	// Marker provides access to the gtsmodel Marker database cache.
	Marker structr.Cache[*gtsmodel.Marker]

	// Media provides access to the gtsmodel Media database cache.
	Media structr.Cache[*gtsmodel.MediaAttachment]

	// Mention provides access to the gtsmodel Mention database cache.
	Mention structr.Cache[*gtsmodel.Mention]

	// Notification provides access to the gtsmodel Notification database cache.
	Notification structr.Cache[*gtsmodel.Notification]

	// Poll provides access to the gtsmodel Poll database cache.
	Poll structr.Cache[*gtsmodel.Poll]

	// PollVote provides access to the gtsmodel PollVote database cache.
	PollVote structr.Cache[*gtsmodel.PollVote]

	// PollVoteIDs provides access to the poll vote IDs list database cache.
	PollVoteIDs *SliceCache[string]

	// Report provides access to the gtsmodel Report database cache.
	Report structr.Cache[*gtsmodel.Report]

	// Status provides access to the gtsmodel Status database cache.
	Status structr.Cache[*gtsmodel.Status]

	// StatusFave provides access to the gtsmodel StatusFave database cache.
	StatusFave structr.Cache[*gtsmodel.StatusFave]

	// StatusFaveIDs provides access to the status fave IDs list database cache.
	StatusFaveIDs *SliceCache[string]

	// Tag provides access to the gtsmodel Tag database cache.
	Tag structr.Cache[*gtsmodel.Tag]

	// Tombstone provides access to the gtsmodel Tombstone database cache.
	Tombstone structr.Cache[*gtsmodel.Tombstone]

	// ThreadMute provides access to the gtsmodel ThreadMute database cache.
	ThreadMute structr.Cache[*gtsmodel.ThreadMute]

	// User provides access to the gtsmodel User database cache.
	User structr.Cache[*gtsmodel.User]

	// Webfinger provides access to the webfinger URL cache.
	// TODO: move out of GTS caches since unrelated to DB.
	Webfinger *ttl.Cache[string, string] // TTL=24hr, sweep=5min
}

type SliceCache added in v0.11.0

type SliceCache[T any] struct {
	*simple.Cache[string, []T]
}

SliceCache wraps a simple.Cache to provide simple loader-callback functions for fetching + caching slices of objects (e.g. IDs).

func (*SliceCache[T]) Load added in v0.11.0

func (c *SliceCache[T]) Load(key string, load func() ([]T, error)) ([]T, error)

Load will attempt to load an existing slice from the cache for the given key, else calling the provided load function and caching the result.

type VisibilityCache added in v0.8.0

type VisibilityCache struct {
	structr.Cache[*CachedVisibility]
}

type VisibilityType added in v0.8.0

type VisibilityType byte

VisibilityType represents a visibility lookup type. We use a byte type here to improve performance in the result cache when generating the key.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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