Documentation ¶
Index ¶
- Constants
- type Cache
- func (c *Cache) Add(entityID flow.Identifier, entity flow.Entity) bool
- func (c *Cache) Adjust(entityID flow.Identifier, f func(flow.Entity) flow.Entity) (flow.Entity, bool)
- func (c Cache) All() map[flow.Identifier]flow.Entity
- func (c *Cache) ByID(entityID flow.Identifier) (flow.Entity, bool)
- func (c *Cache) Clear()
- func (c Cache) Entities() []flow.Entity
- func (c *Cache) Has(entityID flow.Identifier) bool
- func (c *Cache) Hash() flow.Identifier
- func (c Cache) Identifiers() flow.IdentifierList
- func (c *Cache) Rem(entityID flow.Identifier) (flow.Entity, bool)
- func (c Cache) Size() uint
Constants ¶
const DefaultOversizeFactor = uint32(8)
DefaultOversizeFactor determines the default oversizing factor of HeroCache. What is oversize factor? Imagine adding n keys, rounds times to a hash table with a fixed number slots per bucket. The number of buckets can be chosen upon initialization and then never changes. If a bucket is full then the oldest key is ejected, and if that key is too new, this is a bucket overflow. How many buckets are needed to avoid a bucket overflow assuming cryptographic key hashing is used? The overSizeFactor is used to determine the number of buckets. Assume n 16, rounds 3, & slotsPerBucket 3 for the tiny example below showing overSizeFactor 1 thru 6. As overSizeFactor is increased the chance of overflowing a bucket is decreased. With overSizeFactor 1: 8 from 48 keys can be added before bucket overflow. With overSizeFactor 2: 10 from 48 keys can be added before bucket overflow. With overSizeFactor 3: 13 from 48 keys can be added before bucket overflow. With overSizeFactor 4: 15 from 48 keys can be added before bucket overflow. With overSizeFactor 5: 27 from 48 keys can be added before bucket overflow. With overSizeFactor 6: 48 from 48 keys can be added. The default overSizeFactor factor is different in the package code because slotsPerBucket is > 3.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache implements an array-based generic memory pool backed by a fixed total array.
func NewCache ¶
func NewCache(sizeLimit uint32, oversizeFactor uint32, ejectionMode heropool.EjectionMode, logger zerolog.Logger, collector module.HeroCacheMetrics) *Cache
func (*Cache) Adjust ¶
func (c *Cache) Adjust(entityID flow.Identifier, f func(flow.Entity) flow.Entity) (flow.Entity, bool)
Adjust adjusts the entity using the given function if the given identifier can be found. Returns a bool which indicates whether the entity was updated as well as the updated entity.
func (Cache) All ¶
func (c Cache) All() map[flow.Identifier]flow.Entity
All returns all entities stored in the backdata.
func (*Cache) Has ¶
func (c *Cache) Has(entityID flow.Identifier) bool
Has checks if backdata already contains the entity with the given identifier.
func (*Cache) Hash ¶
func (c *Cache) Hash() flow.Identifier
Hash returns the merkle root hash of all entities.
func (Cache) Identifiers ¶
func (c Cache) Identifiers() flow.IdentifierList
Identifiers returns the list of identifiers of entities stored in the backdata.