Documentation
¶
Index ¶
- Variables
- type CacheStore
- type ErrHandler
- type Handler
- type PrometheusMonitor
- type ReadProcessType
- type Repository
- func (rep *Repository) Disable(ctx context.Context, id ResourceKey, force bool) error
- func (rep *Repository) Fetch(ctx context.Context, id ResourceKey, syncCache bool) (*Resource, error)
- func (rep *Repository) Find(ctx context.Context, id ResourceKey) (*Resource, error)
- func (rep *Repository) SyncCache(ctx context.Context, id ResourceKey) (*Resource, error)
- type RepositoryHandler
- type RepositoryHook
- type RepositoryMonitor
- type Resource
- type ResourceHandler
- type ResourceHandlers
- func (handlers *ResourceHandlers) BeforeResourceCache(key ResourceKey)
- func (handlers *ResourceHandlers) DisableCache(ctx context.Context, id ResourceKey) error
- func (handlers *ResourceHandlers) Downgrading(ctx context.Context, key ResourceKey, err error) (*Resource, error)
- func (handlers *ResourceHandlers) FetchFromStore(ctx context.Context, id ResourceKey) (*Resource, error)
- func (handlers *ResourceHandlers) FindFromCache(ctx context.Context, id ResourceKey) (*Resource, error)
- func (handlers *ResourceHandlers) SetHandler(handler ResourceHandler)
- func (handlers *ResourceHandlers) ThroughOnCacheErr(ctx context.Context, key ResourceKey, err error) (goThrough bool)
- func (handlers *ResourceHandlers) UpdateCache(ctx context.Context, data Resource) error
- type ResourceKey
- type SourceDataStore
- type Span
- type Tracers
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type CacheStore ¶
type CacheStore interface { // update cached resource UpdateCache(ctx context.Context, data Resource) error // find resource in cache, return nil if not in cache FindFromCache(ctx context.Context, id ResourceKey) (*Resource, error) // disable cache DisableCache(ctx context.Context, id ResourceKey) error }
cache repository used for cache store
type ErrHandler ¶
type ErrHandler interface { // go through on cache err, store limiter will also work ThroughOnCacheErr(ctx context.Context, resource ResourceKey, err error) (goThrough bool) //data downgrading if find data has err Downgrading(ctx context.Context, resource ResourceKey, err error) (*Resource, error) }
type Handler ¶
type Handler struct { Key ResourceKey // contains filtered or unexported fields }
type PrometheusMonitor ¶
type PrometheusMonitor struct {
// contains filtered or unexported fields
}
func NewPrometheusMonitor ¶
func NewPrometheusMonitor(name string) *PrometheusMonitor
func (*PrometheusMonitor) AddFindRecord ¶
func (monitor *PrometheusMonitor) AddFindRecord(key ResourceKey, hit bool, downgrade bool, err error, duration time.Duration)
func (*PrometheusMonitor) Controller ¶
func (monitor *PrometheusMonitor) Controller() prometheus.Collector
type ReadProcessType ¶
type ReadProcessType int
const ( ReadFromCache ReadProcessType = 1 ReadFromStore ReadProcessType = 1 ReadFromDowngrade ReadProcessType = 1 )
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
func NewRepository ¶
func NewRepository(handler *ResourceHandlers, monitor RepositoryMonitor, logger *zap.Logger, throughLimit rate.Limit) *Repository
func (*Repository) Disable ¶
func (rep *Repository) Disable(ctx context.Context, id ResourceKey, force bool) error
Disable disable the cache.
func (*Repository) Fetch ¶
func (rep *Repository) Fetch(ctx context.Context, id ResourceKey, syncCache bool) (*Resource, error)
Fetch resource from source data store. Update cache if syncCache is true. This method can be used to update cache!
func (*Repository) Find ¶
func (rep *Repository) Find(ctx context.Context, id ResourceKey) (*Resource, error)
find resource in cache first, if not exists than read from store and update to cache
func (*Repository) SyncCache ¶
func (rep *Repository) SyncCache(ctx context.Context, id ResourceKey) (*Resource, error)
enforce sync cache from store
type RepositoryHandler ¶
type RepositoryHandler interface { SourceDataStore CacheStore RepositoryMonitor RepositoryHook }
gather business logic into handler
type RepositoryHook ¶
type RepositoryHook interface {
BeforeResourceCache(key ResourceKey)
}
monitor interface
type RepositoryMonitor ¶
type RepositoryMonitor interface {
AddFindRecord(key ResourceKey, hit bool, downgrade bool, err error, total time.Duration)
}
monitor interface
type Resource ¶
type Resource struct { Key ResourceKey Data interface{} }
type ResourceHandler ¶
type ResourceHandler struct { Category string FetchFromStoreFunc func(ctx context.Context, id ResourceKey) (*Resource, error) UpdateCacheFunc func(ctx context.Context, data Resource) error FindFromCacheFunc func(ctx context.Context, id ResourceKey) (*Resource, error) DisableCache func(ctx context.Context, id ResourceKey) error ThroughOnCacheErr func(ctx context.Context, resource ResourceKey, err error) (goThrough bool) // go through on cache err, store limiter will also work DowngradeOnErr func(ctx context.Context, resource ResourceKey, err error) (*Resource, error) //data downgrading BeforeResourceCacheFunc func(key ResourceKey) }
type ResourceHandlers ¶
type ResourceHandlers struct {
// contains filtered or unexported fields
}
func NewResourceHandlers ¶
func NewResourceHandlers() *ResourceHandlers
func (*ResourceHandlers) BeforeResourceCache ¶
func (handlers *ResourceHandlers) BeforeResourceCache(key ResourceKey)
func (*ResourceHandlers) DisableCache ¶
func (handlers *ResourceHandlers) DisableCache(ctx context.Context, id ResourceKey) error
func (*ResourceHandlers) Downgrading ¶
func (handlers *ResourceHandlers) Downgrading(ctx context.Context, key ResourceKey, err error) (*Resource, error)
data downgrading if find data has err
func (*ResourceHandlers) FetchFromStore ¶
func (handlers *ResourceHandlers) FetchFromStore(ctx context.Context, id ResourceKey) (*Resource, error)
func (*ResourceHandlers) FindFromCache ¶
func (handlers *ResourceHandlers) FindFromCache(ctx context.Context, id ResourceKey) (*Resource, error)
func (*ResourceHandlers) SetHandler ¶
func (handlers *ResourceHandlers) SetHandler(handler ResourceHandler)
func (*ResourceHandlers) ThroughOnCacheErr ¶
func (handlers *ResourceHandlers) ThroughOnCacheErr(ctx context.Context, key ResourceKey, err error) (goThrough bool)
go through on cache err, store limiter will also work
func (*ResourceHandlers) UpdateCache ¶
func (handlers *ResourceHandlers) UpdateCache(ctx context.Context, data Resource) error
type ResourceKey ¶
type SourceDataStore ¶
type SourceDataStore interface { // return nil, if not exists FetchFromStore(ctx context.Context, id ResourceKey) (*Resource, error) }
source data store
Click to show internal directories.
Click to hide internal directories.