Documentation ¶
Overview ¶
Package epcache implements a distributed cache system development framework.
Index ¶
- type ByteView
- type CacheStats
- type CacheType
- type Getter
- type GetterFunc
- type GrpcPool
- type GrpcPoolOptions
- type LimitMode
- type LoadError
- type NoPeer
- type Node
- func (n *Node) CacheStats(ctype CacheType) CacheStats
- func (n *Node) Get(ctx context.Context, key string) (ByteView, error)
- func (n *Node) OnRemove(key string)
- func (n *Node) OnUpdate(key string, value []byte)
- func (n *Node) RegisterPeers(peers PeerAgent)
- func (n *Node) ResetLimiter()
- func (n *Node) SetFilter(size uint32)
- func (n *Node) SetLimiter(rate int, cap int, mode LimitMode)
- type PeerAgent
- type ProtoPeer
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByteView ¶
type ByteView struct {
// contains filtered or unexported fields
}
ByteView holds an immutable view of bytes, it should be used as a value type, not a pointer type.
func (ByteView) Equal ¶ added in v1.7.2
Equal returns whether the bytes in bv are the same as the bytes in bv2.
func (ByteView) EqualBytes ¶ added in v1.7.2
EqualBytes returns whether the bytes in bv are the same as the bytes b2.
type CacheStats ¶
type Getter ¶
type Getter interface { // Get depends on users' concrete implementation. // Context's deadline should be treated properly if existed. Get(ctx context.Context, key string) ([]byte, error) }
Getter loads data from source, like a DB.
type GetterFunc ¶
GetterFunc indicates Getter might just be a func.
type GrpcPool ¶
type GrpcPool struct { pb.UnimplementedEPCacheServer // contains filtered or unexported fields }
func NewGrpcPool ¶
func NewGrpcPool(self string, registry []string, mqBroker string, opts *GrpcPoolOptions) *GrpcPool
NewGrpcPool returns a GrpcPool instance.
registry: The listening addresses of the etcd cluster. mqBroker: The listening address of the MQ broker.
type GrpcPoolOptions ¶
type GrpcPoolOptions struct { Prefix string Exchange string Replicas int HashFn consistenthash.Hash }
GrpcPoolOptions are options to build a GrpcPool instance.
Prefix: The etcd namespace to which an EPCache cluster instance belongs, default `epcache/`. Exchange: The MQ exchange used by an EPCache cluster instance, default `epcache`. Replicas: The replicas of each node in hash ring, default `50`. HashFn: The hashing function used for consistent hash, default `CRC32`.
type LoadError ¶
type LoadError string
const ErrNotFound LoadError = "key not found in data source"
ErrNotFound must be returned when Getter can't found the data.
type NoPeer ¶
type NoPeer struct{}
NoPeer is an implementation of PeerAgent, used for nodes running in standalone mode.
type Node ¶ added in v1.10.0
type Node struct { Stats Stats // contains filtered or unexported fields }
Node is TODO
func (*Node) CacheStats ¶ added in v1.10.0
func (n *Node) CacheStats(ctype CacheType) CacheStats
func (*Node) OnRemove ¶ added in v1.10.0
OnRemove removes data in cache and then syncs to all peers using MQ. This must be called when data in source is purged to ensure consistency.
func (*Node) OnUpdate ¶ added in v1.10.0
OnUpdate updates data in cache and then syncs to all peers using MQ. This must be called when data in source is changed to ensure consistency.
func (*Node) RegisterPeers ¶ added in v1.10.0
RegisterPeers specifies PeerPicker for a node, e.g. NoPeer, GrpcPool or any that implements the PeerPicker.
func (*Node) ResetLimiter ¶ added in v1.10.0
func (n *Node) ResetLimiter()
ResetLimiter disables a rate limiter.
type Stats ¶
type Stats struct { Reqs int64 Gets int64 Hits int64 Loads int64 LoadsDeduped int64 // after singleflight LocalLoads int64 LocalLoadErrs int64 PeerLoads int64 PeerLoadErrs int64 PeerReqs int64 // requests from peers PeerSyncs int64 // data-syncs from peers LenBlacklist int64 }
Stats are statistics for a node.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package bloomfilter avoids cache penetration.
|
Package bloomfilter avoids cache penetration. |
Package consistenthash implements a ring hash.
|
Package consistenthash implements a ring hash. |
Package lru implements a lru cache.
|
Package lru implements a lru cache. |
Package msgctl reduces messages within a specified interval into one.
|
Package msgctl reduces messages within a specified interval into one. |
Package ratelimit implements a token bucket used for request rate limiting.
|
Package ratelimit implements a token bucket used for request rate limiting. |
Package singleflight provides a duplicate func call suppression mechanism, therefore avoiding cache breakdown.
|
Package singleflight provides a duplicate func call suppression mechanism, therefore avoiding cache breakdown. |