Documentation ¶
Index ¶
- Constants
- Variables
- type AtomicCache
- type BufferItem
- type LookupRecord
- type Option
- func OptionGcStarter(option uint32) Option
- func OptionMaxRecords(option int) Option
- func OptionMaxShardsLarge(option int) Option
- func OptionMaxShardsMedium(option int) Option
- func OptionMaxShardsSmall(option int) Option
- func OptionRecordSizeLarge(option int) Option
- func OptionRecordSizeMedium(option int) Option
- func OptionRecordSizeSmall(option int) Option
- type Options
- type Record
- type Shard
- type ShardsLookup
Constants ¶
const ( // SMSH - Small Shards section SMSH = iota + 1 // MDSH - Medium Shards section MDSH // LGSH - Large Shards section LGSH )
Constans below are used for shard section identification.
Variables ¶
var ( ErrNotFound = errors.New("record not found") ErrDataLimit = errors.New("cannot create new record: it violates data limit") ErrFullMemory = errors.New("cannot create new rocord: memory is full") )
Internal cache errors
Functions ¶
This section is empty.
Types ¶
type AtomicCache ¶
type AtomicCache struct { // RWMutex is used for access to shards array. sync.RWMutex // Size of byte array used for memory allocation at small shard section. RecordSizeSmall int // Size of byte array used for memory allocation at medium shard section. RecordSizeMedium int // Size of byte array used for memory allocation at large shard section. RecordSizeLarge int // Maximum records per shard. MaxRecords int // Maximum small shards which can be allocated in cache memory. MaxShardsSmall int // Maximum medium shards which can be allocated in cache memory. MaxShardsMedium int // Maximum large shards which can be allocated in cache memory. MaxShardsLarge int // Garbage collector starter (run garbage collection every X memory sets). GcStarter uint32 // Garbage collector counter for starter. GcCounter uint32 // contains filtered or unexported fields }
AtomicCache structure represents whole cache memory.
func New ¶
func New(opts ...Option) *AtomicCache
New initialize whole cache memory with one allocated shard.
func (*AtomicCache) Get ¶
func (a *AtomicCache) Get(key interface{}) ([]byte, error)
Get returns list of bytes if record is present in cache memory. If record is not found, then error is returned and list is nil.
func (*AtomicCache) Set ¶
func (a *AtomicCache) Set(key interface{}, data []byte, expire time.Duration) error
Set store data to cache memory. If key/record is already in memory, then data are replaced. If not, it checks if there are some allocated shard with empty space for data. If there is no empty space, new shard is allocated. Otherwise some valid record (FIFO queue) is deleted and new one is stored.
type BufferItem ¶ added in v1.0.0
BufferItem is used for buffer, which contains all unattended cache set request.
type LookupRecord ¶
LookupRecord represents item in lookup table. One record contains index of shard and record. So we can determine which shard access and which record of shard to get. Record also contains expiration time.
type Option ¶
type Option func(*Options)
Option specification for Printer package.
func OptionGcStarter ¶
OptionGcStarter option specification.
func OptionMaxRecords ¶
OptionMaxRecords option specification.
func OptionMaxShardsLarge ¶ added in v1.0.0
OptionMaxShardsLarge option specification.
func OptionMaxShardsMedium ¶ added in v1.0.0
OptionMaxShardsMedium option specification.
func OptionMaxShardsSmall ¶ added in v1.0.0
OptionMaxShardsSmall option specification.
func OptionRecordSizeLarge ¶ added in v1.0.0
OptionRecordSizeLarge option specification.
func OptionRecordSizeMedium ¶ added in v1.0.0
OptionRecordSizeMedium option specification.
func OptionRecordSizeSmall ¶ added in v1.0.0
OptionRecordSizeSmall option specification.
type Options ¶
type Options struct { // Size of byte array used for memory allocation at small shard section. RecordSizeSmall int // Size of byte array used for memory allocation at medium shard section. RecordSizeMedium int // Size of byte array used for memory allocation at large shard section. RecordSizeLarge int // Maximum records per shard. MaxRecords int // Maximum small shards which can be allocated in cache memory. MaxShardsSmall int // Maximum medium shards which can be allocated in cache memory. MaxShardsMedium int // Maximum large shards which can be allocated in cache memory. MaxShardsLarge int // Garbage collector starter (run garbage collection every X sets). GcStarter uint32 }
Options are used for AtomicCache construct function.
type Record ¶
Record structure represents one record stored in cache memory.
func NewRecord ¶
NewRecord initialize one new record and return pointer to them. During initialization is allocated maximum size of record. So we have record which is smaller than maximum size, then we set `alloc` property. It specifies how many bytes are used. It prevents garbage collector to take action.
func (*Record) Free ¶
func (r *Record) Free()
Free set alloc property to 0. Through this action, we empty memory of record without calling garbage collector.
func (*Record) Get ¶
Get returns bytes based on size of virtual allocation. It means that it returns only specific count of bytes, based on alloc property. If array on output is empty, then record is not exists.
func (*Record) GetAllocated ¶
GetAllocated returns size of allocated bytes.
func (*Record) GetDataLength ¶
GetDataLength returns real size of allocated bytes in memory.
type Shard ¶
Shard structure contains multiple slots for records.
func NewShard ¶
NewShard initialize list of records with specified size. List is stored in property records and every record has it's own unique id (id is not propagated to record instance). Argument slotCount represents number of records in shard and slotSize represents size of one record.
func (*Shard) Get ¶
Get returns bytes from shard memory based on index. If array on output is empty, then record is not exists.
func (*Shard) GetSlotsAvail ¶
GetSlotsAvail returns number of available memory slots of shard.
type ShardsLookup ¶ added in v1.0.0
type ShardsLookup struct {
// contains filtered or unexported fields
}
ShardsLookup represents data structure for for each shards section. In each section we have different size of records in that shards.