Documentation ¶
Index ¶
- Variables
- type CacheHandlers
- type CacheObject
- func (s *CacheObject) GetBusiness() string
- func (s *CacheObject) GetNotifier() *common.Notifier
- func (s *CacheObject) GetRevision() string
- func (s *CacheObject) IsInValid() bool
- func (s *CacheObject) LoadValue(updateVisitTime bool) interface{}
- func (s *CacheObject) MakeInValid(err model.SDKError)
- func (s *CacheObject) OnServiceUpdate(event *serverconnector.ServiceEvent)
- func (s *CacheObject) SetValue(cacheValue model.RegistryValue)
- type CachedStatus
- type LocalCache
- func (g *LocalCache) CreateDefaultInstanceLocalValue(instID string) local.InstanceLocalValue
- func (g *LocalCache) Destroy() error
- func (g *LocalCache) GetInstances(svcKey *model.ServiceKey, includeCache bool, isInternalRequest bool) model.ServiceInstances
- func (g *LocalCache) GetServiceRateLimitRule(key *model.ServiceKey, includeCache bool) model.ServiceRule
- func (g *LocalCache) GetServiceRouteRule(key *model.ServiceKey, includeCache bool) model.ServiceRule
- func (g *LocalCache) GetServiceRule(svcEventKey *model.ServiceEventKey, includeCache bool) model.ServiceRule
- func (g *LocalCache) GetServicesByMeta(key *model.ServiceKey, includeCache bool) model.Services
- func (g *LocalCache) Init(ctx *plugin.InitContext) error
- func (g *LocalCache) LoadInstances(svcKey *model.ServiceKey) (*common.Notifier, error)
- func (g *LocalCache) LoadPersistedMessage(file string, msg proto.Message) error
- func (g *LocalCache) LoadServiceRateLimitRule(key *model.ServiceKey) (*common.Notifier, error)
- func (g *LocalCache) LoadServiceRouteRule(key *model.ServiceKey) (*common.Notifier, error)
- func (g *LocalCache) LoadServiceRule(svcEventKey *model.ServiceEventKey) (*common.Notifier, error)
- func (g *LocalCache) LoadServices(key *model.ServiceKey) (*common.Notifier, error)
- func (g *LocalCache) Name() string
- func (g *LocalCache) PersistMessage(file string, message proto.Message) error
- func (g *LocalCache) Start() error
- func (g *LocalCache) Type() common.Type
- func (g *LocalCache) UnwatchService(svcEventKey model.ServiceEventKey)
- func (g *LocalCache) UpdateInstances(svcUpdateReq *localregistry.ServiceUpdateRequest) error
- func (g *LocalCache) WatchService(svcEventKey model.ServiceEventKey)
Constants ¶
This section is empty.
Variables ¶
var ( // CachedStatusToPresent 将缓存状态转换为present状态 CachedStatusToPresent = map[CachedStatus]string{ CacheAdded: "CacheAdded", CacheChanged: "CacheChanged", CacheNotChanged: "CacheNotChanged", CacheEmptyButNotChanged: "CacheEmptyButNotChanged", CacheDeleted: "CacheDeleted", } )
Functions ¶
This section is empty.
Types ¶
type CacheHandlers ¶
type CacheHandlers struct { // CompareMessage 消息比较,返回比较结果 CompareMessage func(cacheValue interface{}, newMessage proto.Message) CachedStatus // MessageToCacheValue 原始消息转换为缓存对象 MessageToCacheValue func(cacheValue interface{}, newMessage proto.Message, svcLocalValue local.ServiceLocalValue, cacheLoaded bool) model.RegistryValue // OnEventDeleted 缓存被删除 OnEventDeleted func(key *model.ServiceEventKey, cacheValue interface{}) }
CacheHandlers 不同的事件回调函数
type CacheObject ¶
type CacheObject struct { Handler CacheHandlers // contains filtered or unexported fields }
CacheObject 缓存值的管理基类
func NewCacheObject ¶
func NewCacheObject( handler CacheHandlers, registry *LocalCache, serviceValueKey *model.ServiceEventKey) *CacheObject
NewCacheObject 创建缓存对象
func NewCacheObjectWithInitValue ¶
func NewCacheObjectWithInitValue(handler CacheHandlers, registry *LocalCache, serviceValueKey *model.ServiceEventKey, message proto.Message) *CacheObject
NewCacheObjectWithInitValue 创建带初始值的缓存对象
func (*CacheObject) GetNotifier ¶
func (s *CacheObject) GetNotifier() *common.Notifier
GetNotifier 获取通知对象
func (*CacheObject) LoadValue ¶
func (s *CacheObject) LoadValue(updateVisitTime bool) interface{}
LoadValue 判断缓存值是否可读取
func (*CacheObject) MakeInValid ¶
func (s *CacheObject) MakeInValid(err model.SDKError)
MakeInValid 将本缓存值为不可用,只用于首次请求时,向后端connector监听失败的场景
func (*CacheObject) OnServiceUpdate ¶
func (s *CacheObject) OnServiceUpdate(event *serverconnector.ServiceEvent)
OnServiceUpdate 服务远程实例更新事件到来后的回调操作
func (*CacheObject) SetValue ¶
func (s *CacheObject) SetValue(cacheValue model.RegistryValue)
SetValue 设置缓存对象
type CachedStatus ¶
type CachedStatus int
CachedStatus 缓存状态
const ( // CacheAdded 缓存数据从无到有 CacheAdded CachedStatus = iota + 1 // CacheChanged 缓存已存在,发生了数据改变 CacheChanged // CacheNotChanged 缓存未改变 CacheNotChanged // CacheEmptyButNotChanged 缓存不存在,但是server返回DataNotChanged CacheEmptyButNotChanged // CacheDeleted 服务数据已经被删除 CacheDeleted )
type LocalCache ¶
type LocalCache struct { *plugin.PluginBase *common.RunContext // contains filtered or unexported fields }
LocalCache 基于内存的本地缓存策略
func (*LocalCache) CreateDefaultInstanceLocalValue ¶
func (g *LocalCache) CreateDefaultInstanceLocalValue(instID string) local.InstanceLocalValue
CreateDefaultInstanceLocalValue 创建默认的实例本地信息
func (*LocalCache) GetInstances ¶
func (g *LocalCache) GetInstances(svcKey *model.ServiceKey, includeCache bool, isInternalRequest bool) model.ServiceInstances
GetInstances 获取服务实例列表
func (*LocalCache) GetServiceRateLimitRule ¶
func (g *LocalCache) GetServiceRateLimitRule(key *model.ServiceKey, includeCache bool) model.ServiceRule
GetServiceRateLimitRule 非阻塞获取限流规则
func (*LocalCache) GetServiceRouteRule ¶
func (g *LocalCache) GetServiceRouteRule(key *model.ServiceKey, includeCache bool) model.ServiceRule
GetServiceRouteRule 非阻塞获取配置信息
func (*LocalCache) GetServiceRule ¶
func (g *LocalCache) GetServiceRule(svcEventKey *model.ServiceEventKey, includeCache bool) model.ServiceRule
GetServiceRule 非阻塞获取规则信息
func (*LocalCache) GetServicesByMeta ¶
func (g *LocalCache) GetServicesByMeta(key *model.ServiceKey, includeCache bool) model.Services
GetServicesByMeta 非阻塞获取服务列表
func (*LocalCache) LoadInstances ¶
func (g *LocalCache) LoadInstances(svcKey *model.ServiceKey) (*common.Notifier, error)
LoadInstances 发起实例查询
func (*LocalCache) LoadPersistedMessage ¶
func (g *LocalCache) LoadPersistedMessage(file string, msg proto.Message) error
LoadPersistedMessage 从文件中加载PB缓存
func (*LocalCache) LoadServiceRateLimitRule ¶
func (g *LocalCache) LoadServiceRateLimitRule(key *model.ServiceKey) (*common.Notifier, error)
LoadServiceRateLimitRule 非阻塞发起限流规则加载
func (*LocalCache) LoadServiceRouteRule ¶
func (g *LocalCache) LoadServiceRouteRule(key *model.ServiceKey) (*common.Notifier, error)
LoadServiceRouteRule 非阻塞发起配置加载
func (*LocalCache) LoadServiceRule ¶
func (g *LocalCache) LoadServiceRule(svcEventKey *model.ServiceEventKey) (*common.Notifier, error)
LoadServiceRule 非阻塞发起规则加载
func (*LocalCache) LoadServices ¶
func (g *LocalCache) LoadServices(key *model.ServiceKey) (*common.Notifier, error)
LoadServices 非阻塞加载批量服务
func (*LocalCache) PersistMessage ¶
func (g *LocalCache) PersistMessage(file string, message proto.Message) error
PersistMessage 对PB缓存进行持久化
func (*LocalCache) UnwatchService ¶ added in v1.4.0
func (g *LocalCache) UnwatchService(svcEventKey model.ServiceEventKey)
UnwatchService 服务反订阅
func (*LocalCache) UpdateInstances ¶
func (g *LocalCache) UpdateInstances(svcUpdateReq *localregistry.ServiceUpdateRequest) error
UpdateInstances 批量更新服务实例状态,properties存放的是状态值,当前支持2个key 对同一个key的更新,请保持线程安全 1. ReadyToServe: 故障熔断标识,true or false 2. DynamicWeight:动态权重值
func (*LocalCache) WatchService ¶
func (g *LocalCache) WatchService(svcEventKey model.ServiceEventKey)
WatchService 服务订阅