github.com/LagrangeDev/LagrangeGo@v0.0.0-20240512064304-ad4a85e10cb4/client/internal/cache/operation.go (about)

     1  package cache
     2  
     3  import (
     4  	"github.com/LagrangeDev/LagrangeGo/client/entity"
     5  )
     6  
     7  func (c *Cache) RefreshAll(friendCache map[uint32]*entity.Friend, groupCache map[uint32]*entity.Group, groupMemberCache map[uint32]map[uint32]*entity.GroupMember) {
     8  	c.RefreshAllFriend(friendCache)
     9  	c.RefreshAllGroup(groupCache)
    10  	c.RefreshAllGroupMembers(groupMemberCache)
    11  }
    12  
    13  // RefreshFriend 刷新一个好友的缓存
    14  func (c *Cache) RefreshFriend(friend *entity.Friend) {
    15  	setCacheOf(c, friend.Uin, friend)
    16  }
    17  
    18  // RefreshAllFriend 刷新所有好友缓存
    19  func (c *Cache) RefreshAllFriend(friendCache map[uint32]*entity.Friend) {
    20  	refreshAllCacheOf(c, friendCache)
    21  }
    22  
    23  // RefreshGroupMember 刷新指定群的一个群成员缓存
    24  func (c *Cache) RefreshGroupMember(groupUin uint32, groupMember *entity.GroupMember) {
    25  	group, ok := getCacheOf[Cache](c, groupUin)
    26  	if !ok {
    27  		group = &Cache{}
    28  		setCacheOf(c, groupUin, group)
    29  	}
    30  	setCacheOf(group, groupMember.Uin, groupMember)
    31  }
    32  
    33  // RefreshGroupMembers 刷新一个群内的所有群成员缓存
    34  func (c *Cache) RefreshGroupMembers(groupUin uint32, groupMembers map[uint32]*entity.GroupMember) {
    35  	newc := &Cache{}
    36  	for k, v := range groupMembers {
    37  		setCacheOf(newc, k, v)
    38  	}
    39  	setCacheOf(c, groupUin, newc)
    40  }
    41  
    42  // RefreshAllGroupMembers 刷新所有群的群员缓存
    43  func (c *Cache) RefreshAllGroupMembers(groupMemberCache map[uint32]map[uint32]*entity.GroupMember) {
    44  	newc := make(map[uint32]*Cache, len(groupMemberCache)*2)
    45  	for groupUin, v := range groupMemberCache {
    46  		group := &Cache{}
    47  		refreshAllCacheOf(group, v)
    48  		newc[groupUin] = group
    49  	}
    50  	refreshAllCacheOf(c, newc)
    51  }
    52  
    53  // RefreshGroup 刷新一个群的群信息缓存
    54  func (c *Cache) RefreshGroup(group *entity.Group) {
    55  	setCacheOf(c, group.GroupUin, group)
    56  }
    57  
    58  // RefreshAllGroup 刷新所有群的群信息缓存
    59  func (c *Cache) RefreshAllGroup(groupCache map[uint32]*entity.Group) {
    60  	refreshAllCacheOf(c, groupCache)
    61  }