cache

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewInCache

func NewInCache(db chat.Store) chat.Store

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache wraps a chat.Store, caching what is fixed at a chat's creation and so can never go stale: DM membership checks, a DM's member list, and a group's participation rules. A DM's membership never changes, so a confirmed DM member, and the DM's member pair, are safe to cache. Group membership is mutable — and can be mutated by other processes, which this cache can never observe — so group membership checks and member lists always defer to the backing store. The rest of the store is passed straight through, viewer state included: a user's state is theirs to change at any time, and its reads are already one strongly consistent query, so nothing of it is held.

func (*Cache) AddGroupMembers added in v1.26.0

func (c *Cache) AddGroupMembers(ctx context.Context, chatID *commonpb.ChatId, userIDs []*commonpb.UserId) (bool, chat.RosterSummary, error)

func (*Cache) AdvanceLastMessage

func (c *Cache) AdvanceLastMessage(ctx context.Context, chatID *commonpb.ChatId, messageID *messagingpb.MessageId, ts time.Time) (bool, []*commonpb.UserId, error)

func (*Cache) ClearMute added in v1.32.0

func (c *Cache) ClearMute(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId) (chat.ViewerState, bool, error)

func (*Cache) EditGroup added in v1.32.0

func (c *Cache) EditGroup(ctx context.Context, chatID *commonpb.ChatId, edit chat.GroupEdit) error

func (*Cache) GetChatByID

func (c *Cache) GetChatByID(ctx context.Context, chatID *commonpb.ChatId) (*chat.Chat, error)

func (*Cache) GetDmFeedPage

func (c *Cache) GetDmFeedPage(ctx context.Context, userID *commonpb.UserId, chatType chatpb.ChatType, snapshot time.Time, cursor *chat.DmFeedCursor, limit int) ([]*chat.Chat, error)

func (*Cache) GetGroupChatsForUser added in v1.30.0

func (c *Cache) GetGroupChatsForUser(ctx context.Context, userID *commonpb.UserId) ([]*chat.Chat, error)

func (*Cache) GetGroupChatsForUserByIDs added in v1.30.0

func (c *Cache) GetGroupChatsForUserByIDs(ctx context.Context, userID *commonpb.UserId, chatIDs []*commonpb.ChatId) ([]*chat.Chat, error)

func (*Cache) GetGroupMemberRecords added in v1.32.0

func (c *Cache) GetGroupMemberRecords(ctx context.Context, userID *commonpb.UserId, chatIDs []*commonpb.ChatId) (map[string]chat.GroupMember, error)

func (*Cache) GetGroupMembersPage added in v1.32.0

func (c *Cache) GetGroupMembersPage(ctx context.Context, chatID *commonpb.ChatId, after *commonpb.UserId, limit int) (chat.MembersPage, error)

GetGroupMembersPage passes through: a group's roster is mutable and never cached here, as for GetMembers.

func (*Cache) GetGroupMembershipsForUser added in v1.30.0

func (c *Cache) GetGroupMembershipsForUser(ctx context.Context, userID *commonpb.UserId) ([]chat.GroupMembership, error)

Never cached, for the same reason group IsMember checks are not: group membership is mutable from other processes.

func (*Cache) GetGroupRoster added in v1.32.0

func (c *Cache) GetGroupRoster(ctx context.Context, chatID *commonpb.ChatId) (chat.RosterSummary, []chat.GroupMember, error)

GetGroupRoster, GetGroupRosterPage and GetGroupMemberRecords pass through likewise: each is a read of the mutable membership records.

func (*Cache) GetGroupRosterPage added in v1.32.0

func (c *Cache) GetGroupRosterPage(ctx context.Context, chatID *commonpb.ChatId, after *chat.RosterPosition, limit int) ([]chat.GroupMember, error)

func (*Cache) GetGroupRosterSummaries added in v1.30.0

func (c *Cache) GetGroupRosterSummaries(ctx context.Context, chatIDs []*commonpb.ChatId) (map[string]chat.RosterSummary, error)

func (*Cache) GetGroupRosterSummary added in v1.30.0

func (c *Cache) GetGroupRosterSummary(ctx context.Context, chatID *commonpb.ChatId) (chat.RosterSummary, error)

func (*Cache) GetGroupRules added in v1.30.0

func (c *Cache) GetGroupRules(ctx context.Context, chatID *commonpb.ChatId) (*chatpb.Rules, error)

GetGroupRules is cached, including the absence of rules (a nil result), so a group without any is read once too. Rules are fixed at creation (see chat.Store), so a cached entry is never stale: if rules ever become mutable, this needs invalidation on write. A cached entry is shared by every caller and must be treated as read-only. Errors — including ErrChatNotFound, since the group may be created later — are not cached.

func (*Cache) GetMembers

func (c *Cache) GetMembers(ctx context.Context, chatID *commonpb.ChatId) ([]*commonpb.UserId, error)

GetMembers is cached for a DM: its member pair is fixed at creation, so a list once read is never stale. It is the read behind every DM broadcast (a message, a pointer advance, a reaction, typing), which otherwise costs a store read per event just to find the peer. A group's roster is mutable, so a group's list always defers to the backing store, as IsMember does. Errors — including ErrChatNotFound, since the DM may be created later — are not cached. The caller gets its own copy, so the cached list is never mutated through a result.

func (*Cache) GetMutedCount added in v1.32.0

func (c *Cache) GetMutedCount(ctx context.Context, chatID *commonpb.ChatId) (uint64, error)

func (*Cache) GetMutedUsers added in v1.32.0

func (c *Cache) GetMutedUsers(ctx context.Context, chatID *commonpb.ChatId, now time.Time, limit int) ([]*commonpb.UserId, error)

func (*Cache) GetMutedUsersPage added in v1.32.0

func (c *Cache) GetMutedUsersPage(ctx context.Context, chatID *commonpb.ChatId, now time.Time, lo, hi *commonpb.UserId) ([]*commonpb.UserId, error)

func (*Cache) GetViewerStates added in v1.32.0

func (c *Cache) GetViewerStates(ctx context.Context, userID *commonpb.UserId, chatIDs []*commonpb.ChatId) (map[string]chat.ViewerState, error)

func (*Cache) IsMember

func (c *Cache) IsMember(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId) (bool, error)

func (*Cache) PutChat

func (c *Cache) PutChat(ctx context.Context, ch *chat.Chat) error

func (*Cache) RemoveGroupMember added in v1.26.0

func (c *Cache) RemoveGroupMember(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId) (bool, chat.RosterSummary, error)

func (*Cache) SetGroupPicture added in v1.30.0

func (c *Cache) SetGroupPicture(ctx context.Context, chatID *commonpb.ChatId, blobID *blobpb.BlobId) error

func (*Cache) SetMute added in v1.32.0

func (c *Cache) SetMute(ctx context.Context, chatID *commonpb.ChatId, userID *commonpb.UserId, mute chat.Mute) (chat.ViewerState, bool, error)

Jump to

Keyboard shortcuts

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