cache

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 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.

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) 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) 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) 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) 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

Jump to

Keyboard shortcuts

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