Documentation ¶
Index ¶
- Constants
- Variables
- type CachedVisibility
- type Caches
- func (c *Caches) Init()
- func (c *Caches) OnInvalidateAccount(account *gtsmodel.Account)
- func (c *Caches) OnInvalidateApplication(app *gtsmodel.Application)
- func (c *Caches) OnInvalidateBlock(block *gtsmodel.Block)
- func (c *Caches) OnInvalidateClient(client *gtsmodel.Client)
- func (c *Caches) OnInvalidateConversation(conversation *gtsmodel.Conversation)
- func (c *Caches) OnInvalidateEmojiCategory(category *gtsmodel.EmojiCategory)
- func (c *Caches) OnInvalidateFollow(follow *gtsmodel.Follow)
- func (c *Caches) OnInvalidateFollowRequest(followReq *gtsmodel.FollowRequest)
- func (c *Caches) OnInvalidateInstance(instance *gtsmodel.Instance)
- func (c *Caches) OnInvalidateList(list *gtsmodel.List)
- func (c *Caches) OnInvalidateMedia(media *gtsmodel.MediaAttachment)
- func (c *Caches) OnInvalidatePoll(poll *gtsmodel.Poll)
- func (c *Caches) OnInvalidatePollVote(vote *gtsmodel.PollVote)
- func (c *Caches) OnInvalidateStatus(status *gtsmodel.Status)
- func (c *Caches) OnInvalidateStatusBookmark(bookmark *gtsmodel.StatusBookmark)
- func (c *Caches) OnInvalidateStatusFave(fave *gtsmodel.StatusFave)
- func (c *Caches) OnInvalidateUser(user *gtsmodel.User)
- func (c *Caches) OnInvalidateUserMute(mute *gtsmodel.UserMute)
- func (c *Caches) Start()
- func (c *Caches) Stop()
- func (c *Caches) Sweep(threshold float64)
- type DBCaches
- type SliceCache
- func (c *SliceCache[T]) Cap() int
- func (c *SliceCache[T]) Clear()
- func (c *SliceCache[T]) Init(len, cap int)
- func (c *SliceCache[T]) Invalidate(keys ...string)
- func (c *SliceCache[T]) Len() int
- func (c *SliceCache[T]) Load(key string, load func() ([]T, error)) ([]T, error)
- func (c *SliceCache[T]) Trim(perc float64)
- type StructCache
- func (c *StructCache[T]) Cap() int
- func (c *StructCache[T]) Clear()
- func (c *StructCache[T]) Get(index string, keys ...[]any) []T
- func (c *StructCache[T]) GetOne(index string, key ...any) (T, bool)
- func (c *StructCache[T]) Init(config structr.CacheConfig[T])
- func (c *StructCache[T]) Invalidate(index string, key ...any)
- func (c *StructCache[T]) InvalidateIDs(index string, ids []string)
- func (c *StructCache[T]) Len() int
- func (c *StructCache[T]) LoadIDs(index string, ids []string, load func([]string) ([]T, error)) ([]T, error)
- func (c *StructCache[T]) LoadIDs2Part(index string, id1 string, id2s []string, ...) ([]T, error)
- func (c *StructCache[T]) LoadOne(index string, load func() (T, error), key ...any) (T, error)
- func (c *StructCache[T]) Put(values ...T)
- func (c *StructCache[T]) Store(value T, store func() error) error
- func (c *StructCache[T]) Trim(perc float64)
- type VisibilityCache
- type VisibilityType
Constants ¶
const ( // Possible cache visibility lookup types. VisibilityTypeAccount = VisibilityType('a') VisibilityTypeStatus = VisibilityType('s') VisibilityTypeHome = VisibilityType('h') VisibilityTypePublic = VisibilityType('p') )
Variables ¶
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 { // DB provides access to the collection of // gtsmodel object caches. (used by the database). DB DBCaches // 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 // Webfinger provides access to the webfinger URL cache. Webfinger *ttl.Cache[string, string] // TTL=24hr, sweep=5min // TTL cache of statuses -> filterable text fields. // To ensure up-to-date fields, cache is keyed as: // `[status.ID][status.UpdatedAt.Unix()]` StatusesFilterableFields *ttl.Cache[string, []string] // 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 (*Caches) OnInvalidateApplication ¶ added in v0.16.0
func (c *Caches) OnInvalidateApplication(app *gtsmodel.Application)
func (*Caches) OnInvalidateBlock ¶ added in v0.14.0
func (*Caches) OnInvalidateClient ¶ added in v0.16.0
func (*Caches) OnInvalidateConversation ¶ added in v0.17.0
func (c *Caches) OnInvalidateConversation(conversation *gtsmodel.Conversation)
func (*Caches) OnInvalidateEmojiCategory ¶ added in v0.14.0
func (c *Caches) OnInvalidateEmojiCategory(category *gtsmodel.EmojiCategory)
func (*Caches) OnInvalidateFollow ¶ added in v0.14.0
func (*Caches) OnInvalidateFollowRequest ¶ added in v0.14.0
func (c *Caches) OnInvalidateFollowRequest(followReq *gtsmodel.FollowRequest)
func (*Caches) OnInvalidateInstance ¶ added in v0.17.0
func (*Caches) OnInvalidateList ¶ added in v0.14.0
func (*Caches) OnInvalidateMedia ¶ added in v0.14.0
func (c *Caches) OnInvalidateMedia(media *gtsmodel.MediaAttachment)
func (*Caches) OnInvalidatePoll ¶ added in v0.14.0
func (*Caches) OnInvalidatePollVote ¶ added in v0.14.0
func (*Caches) OnInvalidateStatus ¶ added in v0.14.0
func (*Caches) OnInvalidateStatusBookmark ¶ added in v0.16.0
func (c *Caches) OnInvalidateStatusBookmark(bookmark *gtsmodel.StatusBookmark)
func (*Caches) OnInvalidateStatusFave ¶ added in v0.14.0
func (c *Caches) OnInvalidateStatusFave(fave *gtsmodel.StatusFave)
func (*Caches) OnInvalidateUser ¶ added in v0.14.0
func (*Caches) OnInvalidateUserMute ¶ added in v0.16.0
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
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 DBCaches ¶ added in v0.17.0
type DBCaches struct { // Account provides access to the gtsmodel Account database cache. Account StructCache[*gtsmodel.Account] // AccountNote provides access to the gtsmodel Note database cache. AccountNote StructCache[*gtsmodel.AccountNote] // AccountSettings provides access to the gtsmodel AccountSettings database cache. AccountSettings StructCache[*gtsmodel.AccountSettings] // AccountStats provides access to the gtsmodel AccountStats database cache. AccountStats StructCache[*gtsmodel.AccountStats] // Application provides access to the gtsmodel Application database cache. Application StructCache[*gtsmodel.Application] // Block provides access to the gtsmodel Block (account) database cache. Block StructCache[*gtsmodel.Block] // BlockIDs 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] // Client provides access to the gtsmodel Client database cache. Client StructCache[*gtsmodel.Client] // Conversation provides access to the gtsmodel Conversation database cache. Conversation StructCache[*gtsmodel.Conversation] // ConversationLastStatusIDs provides access to the conversation last status IDs database cache. ConversationLastStatusIDs 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 StructCache[*gtsmodel.Emoji] // EmojiCategory provides access to the gtsmodel EmojiCategory database cache. EmojiCategory StructCache[*gtsmodel.EmojiCategory] // Filter provides access to the gtsmodel Filter database cache. Filter StructCache[*gtsmodel.Filter] // FilterKeyword provides access to the gtsmodel FilterKeyword database cache. FilterKeyword StructCache[*gtsmodel.FilterKeyword] // FilterStatus provides access to the gtsmodel FilterStatus database cache. FilterStatus StructCache[*gtsmodel.FilterStatus] // Follow provides access to the gtsmodel Follow database cache. Follow StructCache[*gtsmodel.Follow] // FollowIDs provides access to the follower / following IDs database cache. // THIS CACHE IS KEYED AS THE FOLLOWING {prefix}{accountID} WHERE PREFIX IS: // // - '>{$accountID}' for following IDs // e.g. FollowIDs.Load(">" + account.ID, func() {}) // which will load a slice of follows IDs FROM account. // // - 'l>{$accountID}' for local following IDs // e.g. FollowIDs.Load("l>" + account.ID, func() {}) // which will load a slice of LOCAL follows IDs FROM account. // // - '<{$accountID}' for follower IDs // e.g. FollowIDs.Load("<" + account.ID, func() {}) // which will load a slice of follows IDs TARGETTING account. // // - 'l<{$accountID}' for local follower IDs // e.g. FollowIDs.Load("l<" + account.ID, func() {}) // which will load a slice of LOCAL follows IDs TARGETTING account. // FollowIDs SliceCache[string] // FollowRequest provides access to the gtsmodel FollowRequest database cache. FollowRequest StructCache[*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: // // - '>{$accountID}' for follow request IDs // e.g. FollowRequestIDs.Load(">" + account.ID, func() {}) // which will load a slice of follow request IDs TARGETTING account. // // - '<{$accountID}' for follow request IDs // e.g. FollowRequestIDs.Load("<" + account.ID, func() {}) // which will load a slice of follow request IDs FROM account. // FollowRequestIDs SliceCache[string] // FollowingTagIDs provides access to account IDs following / tag IDs followed by // account db cache. THIS CACHE IS KEYED AS THE FOLLOWING {prefix}{id} WHERE: // // - '>{$accountID}' for tag IDs followed by account // e.g. FollowingTagIDs.Load(">" + account.ID, func() {}) // which will load a slice of tag IDs followed by account. // // - '<{$tagIDs}' for account IDs following tag // e.g. FollowingTagIDs.Load("<" + tag.ID, func() {}) // which will load a slice of account IDs following tag. // FollowingTagIDs SliceCache[string] // Instance provides access to the gtsmodel Instance database cache. Instance StructCache[*gtsmodel.Instance] // LocalInstance provides caching for // simple + common local instance queries. LocalInstance struct { Domains atomic.Pointer[int] Statuses atomic.Pointer[int] Users atomic.Pointer[int] } // InteractionRequest provides access to the gtsmodel InteractionRequest database cache. InteractionRequest StructCache[*gtsmodel.InteractionRequest] // 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 StructCache[*gtsmodel.List] // ListIDs provides access to the list IDs owned by account / list IDs follow // contained in db cache. THIS CACHE IS KEYED AS FOLLOWING {prefix}{id} WHERE: // // - 'a{$accountID}' for list IDs owned by account // e.g. ListIDs.Load("a" + account.ID, func() {}) // which will load a slice of list IDs owned by account. // // - 'f{$followID}' for list IDs follow contained in // e.g. ListIDs.Load("f" + follow.ID, func() {}) // which will load a slice of list IDs containing follow. // ListIDs SliceCache[string] // ListedIDs provides access to the account IDs in list / follow IDs in // list db cache. THIS CACHE IS KEYED AS FOLLOWING {prefix}{id} WHERE: // // - 'a{listID}' for account IDs in list ID // e.g. ListedIDs.Load("a" + list.ID, func() {}) // which will load a slice of account IDs in list. // // - 'f{listID}' for follow IDs in list ID // e.g. ListedIDs.Load("f" + list.ID, func() {}) // which will load a slice of follow IDs in list. // ListedIDs SliceCache[string] // Marker provides access to the gtsmodel Marker database cache. Marker StructCache[*gtsmodel.Marker] // Media provides access to the gtsmodel Media database cache. Media StructCache[*gtsmodel.MediaAttachment] // Mention provides access to the gtsmodel Mention database cache. Mention StructCache[*gtsmodel.Mention] // Move provides access to the gtsmodel Move database cache. Move StructCache[*gtsmodel.Move] // Notification provides access to the gtsmodel Notification database cache. Notification StructCache[*gtsmodel.Notification] // Poll provides access to the gtsmodel Poll database cache. Poll StructCache[*gtsmodel.Poll] // PollVote provides access to the gtsmodel PollVote database cache. PollVote StructCache[*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 StructCache[*gtsmodel.Report] // SinBinStatus provides access to the gtsmodel SinBinStatus database cache. SinBinStatus StructCache[*gtsmodel.SinBinStatus] // Status provides access to the gtsmodel Status database cache. Status StructCache[*gtsmodel.Status] // StatusBookmark provides access to the gtsmodel StatusBookmark database cache. StatusBookmark StructCache[*gtsmodel.StatusBookmark] // StatusBookmarkIDs provides access to the status bookmark IDs list database cache. StatusBookmarkIDs SliceCache[string] // StatusFave provides access to the gtsmodel StatusFave database cache. StatusFave StructCache[*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 StructCache[*gtsmodel.Tag] // ThreadMute provides access to the gtsmodel ThreadMute database cache. ThreadMute StructCache[*gtsmodel.ThreadMute] // Token provides access to the gtsmodel Token database cache. Token StructCache[*gtsmodel.Token] // Tombstone provides access to the gtsmodel Tombstone database cache. Tombstone StructCache[*gtsmodel.Tombstone] // User provides access to the gtsmodel User database cache. User StructCache[*gtsmodel.User] // UserMute provides access to the gtsmodel UserMute database cache. UserMute StructCache[*gtsmodel.UserMute] // UserMuteIDs provides access to the user mute IDs database cache. UserMuteIDs SliceCache[string] }
type SliceCache ¶ added in v0.11.0
type SliceCache[T any] struct { // contains filtered or unexported fields }
SliceCache wraps a simple.Cache to provide simple loader-callback functions for fetching + caching slices of objects (e.g. IDs).
func (*SliceCache[T]) Cap ¶ added in v0.15.0
func (c *SliceCache[T]) Cap() int
Cap: see simple.Cache{}.Cap().
func (*SliceCache[T]) Clear ¶ added in v0.15.0
func (c *SliceCache[T]) Clear()
Clear: see simple.Cache{}.Clear().
func (*SliceCache[T]) Init ¶ added in v0.15.0
func (c *SliceCache[T]) Init(len, cap int)
Init initializes the cache with given length + capacity.
func (*SliceCache[T]) Invalidate ¶ added in v0.15.0
func (c *SliceCache[T]) Invalidate(keys ...string)
Invalidate: see simple.Cache{}.InvalidateAll().
func (*SliceCache[T]) Len ¶ added in v0.15.0
func (c *SliceCache[T]) Len() int
Len: see simple.Cache{}.Len().
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 cache for key, else calling load function and caching the result.
func (*SliceCache[T]) Trim ¶ added in v0.15.0
func (c *SliceCache[T]) Trim(perc float64)
Trim: see simple.Cache{}.Trim().
type StructCache ¶ added in v0.15.0
type StructCache[StructType any] struct { // contains filtered or unexported fields }
StructCache wraps a structr.Cache{} to simple index caching by name (also to ease update to library version that introduced this). (in the future it may be worth embedding these indexes by name under the main database caches struct which would reduce time required to access cached values).
func (*StructCache[T]) Cap ¶ added in v0.15.0
func (c *StructCache[T]) Cap() int
Cap: see structr.Cache{}.Cap().
func (*StructCache[T]) Clear ¶ added in v0.15.0
func (c *StructCache[T]) Clear()
Clear: see structr.Cache{}.Clear().
func (*StructCache[T]) Get ¶ added in v0.15.0
func (c *StructCache[T]) Get(index string, keys ...[]any) []T
Get calls structr.Cache{}.Get(), using a cached structr.Index{} by 'index' name. Note: this also handles conversion of the untyped (any) keys to structr.Key{} via structr.Index{}.
func (*StructCache[T]) GetOne ¶ added in v0.15.0
func (c *StructCache[T]) GetOne(index string, key ...any) (T, bool)
GetOne calls structr.Cache{}.GetOne(), using a cached structr.Index{} by 'index' name. Note: this also handles conversion of the untyped (any) keys to structr.Key{} via structr.Index{}.
func (*StructCache[T]) Init ¶ added in v0.15.0
func (c *StructCache[T]) Init(config structr.CacheConfig[T])
Init initializes the cache with given structr.CacheConfig{}.
func (*StructCache[T]) Invalidate ¶ added in v0.15.0
func (c *StructCache[T]) Invalidate(index string, key ...any)
Invalidate calls structr.Cache{}.Invalidate(), using a cached structr.Index{} by 'index' name. Note: this also handles conversion of the untyped (any) keys to structr.Key{} via structr.Index{}.
func (*StructCache[T]) InvalidateIDs ¶ added in v0.15.0
func (c *StructCache[T]) InvalidateIDs(index string, ids []string)
InvalidateIDs calls structr.Cache{}.Invalidate(), using a cached structr.Index{} by 'index' name. Note: this also handles conversion of the ID strings to structr.Key{} via structr.Index{}. Strong typing is used for caller convenience.
If you need to invalidate multiple cache keys other than by ID strings, please create another convenience wrapper.
func (*StructCache[T]) Len ¶ added in v0.15.0
func (c *StructCache[T]) Len() int
Len: see structr.Cache{}.Len().
func (*StructCache[T]) LoadIDs ¶ added in v0.15.0
func (c *StructCache[T]) LoadIDs(index string, ids []string, load func([]string) ([]T, error)) ([]T, error)
LoadIDs calls structr.Cache{}.Load(), using a cached structr.Index{} by 'index' name. Note: this also handles conversion of the ID strings to structr.Key{} via structr.Index{}. Strong typing is used for caller convenience.
If you need to load multiple cache keys other than by ID strings, please create another convenience wrapper.
func (*StructCache[T]) LoadIDs2Part ¶ added in v0.17.0
func (c *StructCache[T]) LoadIDs2Part(index string, id1 string, id2s []string, load func(string, []string) ([]T, error)) ([]T, error)
LoadIDs2Part works as LoadIDs, except using a two-part key, where the first part is an ID shared by all the objects, and the second part is a list of per-object IDs.
func (*StructCache[T]) LoadOne ¶ added in v0.15.0
func (c *StructCache[T]) LoadOne(index string, load func() (T, error), key ...any) (T, error)
LoadOne calls structr.Cache{}.LoadOne(), using a cached structr.Index{} by 'index' name. Note: this also handles conversion of the untyped (any) keys to structr.Key{} via structr.Index{}.
func (*StructCache[T]) Put ¶ added in v0.15.0
func (c *StructCache[T]) Put(values ...T)
Put: see structr.Cache{}.Put().
func (*StructCache[T]) Store ¶ added in v0.15.0
func (c *StructCache[T]) Store(value T, store func() error) error
Store: see structr.Cache{}.Store().
func (*StructCache[T]) Trim ¶ added in v0.15.0
func (c *StructCache[T]) Trim(perc float64)
Trim: see structr.Cache{}.Trim().
type VisibilityCache ¶ added in v0.8.0
type VisibilityCache struct { StructCache[*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.