1 Star 0 Fork 0

jack/protoactor-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pid_cache.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
490689386@qq.com 提交于 2025-05-19 14:50 +08:00 . 初始化
package cluster
import (
"gitee.com/wujianhai/protoactor-go/actor"
cmap "github.com/orcaman/concurrent-map"
)
type PidCacheValue struct {
cache cmap.ConcurrentMap
}
func NewPidCache() *PidCacheValue {
pidCache := &PidCacheValue{
cache: cmap.New(),
}
return pidCache
}
func key(identity string, kind string) string {
return identity + "." + kind
}
func (c *PidCacheValue) Get(identity string, kind string) (*actor.PID, bool) {
k := key(identity, kind)
v, ok := c.cache.Get(k)
if !ok {
return nil, false
}
return v.(*actor.PID), true
}
func (c *PidCacheValue) Set(identity string, kind string, pid *actor.PID) {
k := key(identity, kind)
c.cache.Set(k, pid)
}
func (c *PidCacheValue) RemoveByValue(identity string, kind string, pid *actor.PID) {
k := key(identity, kind)
c.cache.RemoveCb(k, func(key string, v interface{}, exists bool) bool {
if !exists {
return false
}
existing, _ := v.(*actor.PID)
return existing.Equal(pid)
})
}
func (c *PidCacheValue) Remove(identity string, kind string) {
k := key(identity, kind)
c.cache.Remove(k)
}
func (c *PidCacheValue) RemoveByMember(member *Member) {
addr := member.Address()
for item := range c.cache.IterBuffered() {
pid, _ := item.Val.(*actor.PID)
if pid.Address == addr {
c.cache.Remove(item.Key)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wujianhai/protoactor-go.git
git@gitee.com:wujianhai/protoactor-go.git
wujianhai
protoactor-go
protoactor-go
5633fe2499dd

搜索帮助