Documentation ¶
Overview ¶
Package cache is a generated protocol buffer package.
It is generated from these files:
index.proto
It has these top-level messages:
IndexMeta IndexItem
Index ¶
- Constants
- Variables
- type Allocator
- type AllocatorPool
- type AllocatorPoolMetrics
- type Cache
- func (c *Cache) Close() error
- func (c *Cache) Del(key string) error
- func (c *Cache) Get(key string) (Item, error)
- func (c *Cache) GetMetrics() CacheMetrics
- func (c *Cache) GetMetricsByShards() []CacheMetrics
- func (c *Cache) GetOptions() CacheOptions
- func (c *Cache) GetStats() CacheStats
- func (c *Cache) GetStatsByShards() []CacheStats
- func (c *Cache) Set(item Item) error
- type CacheData
- type CacheIndex
- func (i *CacheIndex) Close() error
- func (i *CacheIndex) Del(key string) error
- func (i *CacheIndex) Dels(keys []string) error
- func (i *CacheIndex) Get(key string) (*IndexItem, error)
- func (i *CacheIndex) GetIndexMeta() IndexMeta
- func (i *CacheIndex) GetKeys() (n uint64, err error)
- func (i *CacheIndex) Iter(lastkey string, maxIter int, f func(key string, item IndexItem) error) error
- func (i *CacheIndex) Reserve(size int32) (*IndexItem, error)
- func (i *CacheIndex) Set(key string, item *IndexItem) error
- type CacheMetrics
- type CacheOptions
- type CacheStats
- type ConsistentHash
- type IndexItem
- func (*IndexItem) Descriptor() ([]byte, []int)
- func (m *IndexItem) Marshal() (data []byte, err error)
- func (m *IndexItem) MarshalTo(data []byte) (int, error)
- func (*IndexItem) ProtoMessage()
- func (m *IndexItem) Reset()
- func (m *IndexItem) Size() (n int)
- func (m *IndexItem) String() string
- func (i IndexItem) TotalSize() int64
- func (m *IndexItem) Unmarshal(data []byte) error
- type IndexMeta
- func (*IndexMeta) Descriptor() ([]byte, []int)
- func (m IndexMeta) IsValidate(i IndexItem) bool
- func (m *IndexMeta) Marshal() (data []byte, err error)
- func (m *IndexMeta) MarshalTo(data []byte) (int, error)
- func (*IndexMeta) ProtoMessage()
- func (m *IndexMeta) Reset()
- func (m *IndexMeta) Size() (n int)
- func (m *IndexMeta) String() string
- func (m *IndexMeta) Unmarshal(data []byte) error
- type Item
- type Shard
- type ShardOptions
Constants ¶
View Source
const ( MaxShards = 128 MaxValueSize = int64(128 << 20) // 128MB MinShardSize = MaxValueSize + 4096 )
Variables ¶
View Source
var ( ErrNotFound = errors.New("key not found") ErrValueSize = errors.New("value size exceeded") )
View Source
var ( ErrOutOfRange = errors.New("out of data range") ErrHeader = errors.New("header err") ErrShortRead = errors.New("short read") )
View Source
var ( ErrInvalidLengthIndex = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowIndex = fmt.Errorf("proto: integer overflow") )
View Source
var DefualtCacheOptions = CacheOptions{ ShardNum: 16, Size: 32 * MaxValueSize, TTL: 0, Allocator: NewAllocatorPool(), }
View Source
var DefualtShardOptions = ShardOptions{ Size: MinShardSize, TTL: 0, Allocator: NewAllocatorPool(), }
Functions ¶
This section is empty.
Types ¶
type Allocator ¶
func NewAllocatorPool ¶
func NewAllocatorPool() Allocator
type AllocatorPool ¶
type AllocatorPool struct {
// contains filtered or unexported fields
}
func (*AllocatorPool) Free ¶
func (p *AllocatorPool) Free(b []byte)
func (*AllocatorPool) GetMetrics ¶
func (p *AllocatorPool) GetMetrics() AllocatorPoolMetrics
func (*AllocatorPool) Malloc ¶
func (p *AllocatorPool) Malloc(n int) []byte
type AllocatorPoolMetrics ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func (*Cache) GetMetrics ¶
func (c *Cache) GetMetrics() CacheMetrics
func (*Cache) GetMetricsByShards ¶
func (c *Cache) GetMetricsByShards() []CacheMetrics
func (*Cache) GetOptions ¶
func (c *Cache) GetOptions() CacheOptions
func (*Cache) GetStats ¶
func (c *Cache) GetStats() CacheStats
func (*Cache) GetStatsByShards ¶
func (c *Cache) GetStatsByShards() []CacheStats
type CacheIndex ¶
type CacheIndex struct {
// contains filtered or unexported fields
}
func LoadCacheIndex ¶
func LoadCacheIndex(fn string, datasize int64) (*CacheIndex, error)
func (*CacheIndex) Close ¶
func (i *CacheIndex) Close() error
func (*CacheIndex) Del ¶
func (i *CacheIndex) Del(key string) error
func (*CacheIndex) Dels ¶
func (i *CacheIndex) Dels(keys []string) error
func (*CacheIndex) GetIndexMeta ¶
func (i *CacheIndex) GetIndexMeta() IndexMeta
func (*CacheIndex) GetKeys ¶
func (i *CacheIndex) GetKeys() (n uint64, err error)
type CacheMetrics ¶
type CacheMetrics struct { GetTotal int64 // number of get request GetHits int64 // number of items that hit from data GetMisses int64 // number of items that not found GetExpired int64 // number of items that expired when get SetTotal int64 // number of set request DelTotal int64 // number of del request Expired int64 // number of items that expired Evicted int64 // number of items evicted EvictedAge int64 // min age of the last evicted item }
func (*CacheMetrics) Add ¶
func (m *CacheMetrics) Add(o CacheMetrics)
type CacheOptions ¶
type CacheStats ¶
type CacheStats struct { Keys uint64 // number of keys Bytes uint64 // bytes of keys that used LastUpdate int64 // stat time, the stat is async updated }
func (*CacheStats) Add ¶
func (st *CacheStats) Add(o CacheStats)
type ConsistentHash ¶
type ConsistentHash struct {
// contains filtered or unexported fields
}
a simplify consistent hash impelment without weight
func NewConsistentHashTable ¶
func NewConsistentHashTable(n int) ConsistentHash
NewConsistentHashTable creates a ConsistentHash with value[0, n)
func (*ConsistentHash) Get ¶
func (c *ConsistentHash) Get(key string) int
type IndexItem ¶
type IndexItem struct { Term int64 `protobuf:"varint,1,req,name=Term" json:"Term"` Offset int64 `protobuf:"varint,2,req,name=Offset" json:"Offset"` ValueSize int32 `protobuf:"varint,3,req,name=ValueSize" json:"ValueSize"` Timestamp int64 `protobuf:"varint,4,req,name=Timestamp" json:"Timestamp"` TTL uint32 `protobuf:"varint,5,req,name=TTL" json:"TTL"` Flags uint32 `protobuf:"varint,6,req,name=Flags" json:"Flags"` }
func (*IndexItem) Descriptor ¶
func (*IndexItem) ProtoMessage ¶
func (*IndexItem) ProtoMessage()
type IndexMeta ¶
type IndexMeta struct { Term int64 `protobuf:"varint,1,req,name=Term" json:"Term"` Head int64 `protobuf:"varint,2,req,name=Head" json:"Head"` DataSize int64 `protobuf:"varint,3,req,name=DataSize" json:"DataSize"` }
func (*IndexMeta) Descriptor ¶
func (IndexMeta) IsValidate ¶
IsValidate return if the item is validate
func (*IndexMeta) ProtoMessage ¶
func (*IndexMeta) ProtoMessage()
type Item ¶
type Shard ¶
type Shard struct {
// contains filtered or unexported fields
}
func LoadCacheShard ¶
func LoadCacheShard(fn string, options *ShardOptions) (*Shard, error)
func (*Shard) GetMetrics ¶
func (s *Shard) GetMetrics() CacheMetrics
func (*Shard) GetStats ¶
func (s *Shard) GetStats() CacheStats
type ShardOptions ¶
Click to show internal directories.
Click to hide internal directories.