inmemory

package
v1.5.8 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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) GetBusiness

func (s *CacheObject) GetBusiness() string

GetBusiness 获取业务类型

func (*CacheObject) GetNotifier

func (s *CacheObject) GetNotifier() *common.Notifier

GetNotifier 获取通知对象

func (*CacheObject) GetRevision

func (s *CacheObject) GetRevision() string

GetRevision 获取服务对象的版本号

func (*CacheObject) IsInValid

func (s *CacheObject) IsInValid() bool

IsInValid 判断缓存是否不可用

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
)

func (CachedStatus) String

func (c CachedStatus) String() string

String 缓存状态ToString

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

func (g *LocalCache) Destroy() error

Destroy 销毁插件

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

func (g *LocalCache) Init(ctx *plugin.InitContext) error

Init 初始化插件

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

func (g *LocalCache) Name() string

Name 插件名,一个类型下插件名唯一

func (*LocalCache) PersistMessage

func (g *LocalCache) PersistMessage(file string, message proto.Message) error

PersistMessage 对PB缓存进行持久化

func (*LocalCache) Start

func (g *LocalCache) Start() error

Start 启动插件

func (*LocalCache) Type

func (g *LocalCache) Type() common.Type

Type 插件类型

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 服务订阅

Jump to

Keyboard shortcuts

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