Documentation ¶
Index ¶
- Constants
- Variables
- type Builder
- func (b *Builder[K, V]) Build() (*Cache[K, V], error)
- func (b *Builder[K, V]) BuildWithLoader(loader func(ctx context.Context, key K) (Loaded[V], error)) (*LoadingCache[K, V], error)
- func (b *Builder[K, V]) Cost(cost func(v V) int64) *Builder[K, V]
- func (b *Builder[K, V]) Doorkeeper(enabled bool) *Builder[K, V]
- func (b *Builder[K, V]) Hybrid(cache internal.SecondaryCache[K, V]) *HybridBuilder[K, V]
- func (b *Builder[K, V]) Loading(loader func(ctx context.Context, key K) (Loaded[V], error)) *LoadingBuilder[K, V]
- func (b *Builder[K, V]) RemovalListener(listener func(key K, value V, reason RemoveReason)) *Builder[K, V]
- func (b *Builder[K, V]) StringKey(fn func(k K) string) *Builder[K, V]
- func (b *Builder[K, V]) UseEntryPool(enabled bool) *Builder[K, V]
- type Cache
- func (c *Cache[K, V]) Close()
- func (c *Cache[K, V]) Delete(key K)
- func (c *Cache[K, V]) EstimatedSize() int
- func (c *Cache[K, V]) Get(key K) (V, bool)
- func (c *Cache[K, V]) Len() int
- func (c *Cache[K, V]) LoadCache(version uint64, reader io.Reader) error
- func (c *Cache[K, V]) Range(f func(key K, value V) bool)
- func (c *Cache[K, V]) SaveCache(version uint64, writer io.Writer) error
- func (c *Cache[K, V]) Set(key K, value V, cost int64) bool
- func (c *Cache[K, V]) SetWithTTL(key K, value V, cost int64, ttl time.Duration) bool
- func (c *Cache[K, V]) Stats() Stats
- func (c *Cache[K, V]) Wait()
- type DataBlock
- type HybridBuilder
- func (b *HybridBuilder[K, V]) AdmProbability(p float32) *HybridBuilder[K, V]
- func (b *HybridBuilder[K, V]) Build() (*HybridCache[K, V], error)
- func (b *HybridBuilder[K, V]) Loading(loader func(ctx context.Context, key K) (Loaded[V], error)) *HybridLoadingBuilder[K, V]
- func (b *HybridBuilder[K, V]) Workers(w int) *HybridBuilder[K, V]
- type HybridCache
- func (c *HybridCache[K, V]) Close()
- func (c *HybridCache[K, V]) Delete(key K) error
- func (c *HybridCache[K, V]) Get(key K) (V, bool, error)
- func (c *HybridCache[K, V]) LoadCache(version uint64, reader io.Reader) error
- func (c *HybridCache[K, V]) SaveCache(version uint64, writer io.Writer) error
- func (c *HybridCache[K, V]) Set(key K, value V, cost int64) bool
- func (c *HybridCache[K, V]) SetWithTTL(key K, value V, cost int64, ttl time.Duration) bool
- type HybridLoadingBuilder
- type HybridLoadingCache
- func (c *HybridLoadingCache[K, V]) Close()
- func (c *HybridLoadingCache[K, V]) Delete(key K) error
- func (c *HybridLoadingCache[K, V]) Get(ctx context.Context, key K) (V, error)
- func (c *HybridLoadingCache[K, V]) LoadCache(version uint64, reader io.Reader) error
- func (c *HybridLoadingCache[K, V]) SaveCache(version uint64, writer io.Writer) error
- func (c *HybridLoadingCache[K, V]) Set(key K, value V, cost int64) bool
- func (c *HybridLoadingCache[K, V]) SetWithTTL(key K, value V, cost int64, ttl time.Duration) bool
- type Loaded
- type LoadingBuilder
- type LoadingCache
- func (c *LoadingCache[K, V]) Close()
- func (c *LoadingCache[K, V]) Delete(key K)
- func (c *LoadingCache[K, V]) EstimatedSize() int
- func (c *LoadingCache[K, V]) Get(ctx context.Context, key K) (V, error)
- func (c *LoadingCache[K, V]) Len() int
- func (c *LoadingCache[K, V]) LoadCache(version uint64, reader io.Reader) error
- func (c *LoadingCache[K, V]) Range(f func(key K, value V) bool)
- func (c *LoadingCache[K, V]) SaveCache(version uint64, writer io.Writer) error
- func (c *LoadingCache[K, V]) Set(key K, value V, cost int64) bool
- func (c *LoadingCache[K, V]) SetWithTTL(key K, value V, cost int64, ttl time.Duration) bool
- func (c *LoadingCache[K, V]) Stats() Stats
- func (c *LoadingCache[K, V]) Wait()
- type RemoveReason
- type Serializer
- type Stats
Constants ¶
const ( REMOVED = internal.REMOVED EVICTED = internal.EVICTED EXPIRED = internal.EXPIRED )
const (
ZERO_TTL = 0 * time.Second
)
Variables ¶
var VersionMismatch = internal.VersionMismatch
Functions ¶
This section is empty.
Types ¶
type Builder ¶ added in v0.2.0
type Builder[K comparable, V any] struct { // contains filtered or unexported fields }
func NewBuilder ¶ added in v0.2.0
func NewBuilder[K comparable, V any](maxsize int64) *Builder[K, V]
func (*Builder[K, V]) BuildWithLoader ¶ added in v0.2.0
func (b *Builder[K, V]) BuildWithLoader(loader func(ctx context.Context, key K) (Loaded[V], error)) (*LoadingCache[K, V], error)
BuildWithLoader builds a loading cache client from builder with custom loader function.
func (*Builder[K, V]) Cost ¶ added in v0.2.0
Cost adds dynamic cost function to builder. There is a default cost function which always return 1.
func (*Builder[K, V]) Doorkeeper ¶ added in v0.2.0
Doorkeeper enables/disables doorkeeper. Doorkeeper will drop Set if they are not in bloomfilter yet.
func (*Builder[K, V]) Hybrid ¶ added in v0.3.0
func (b *Builder[K, V]) Hybrid(cache internal.SecondaryCache[K, V]) *HybridBuilder[K, V]
Add secondary cache and switch to HybridBuilder.
func (*Builder[K, V]) Loading ¶ added in v0.3.0
func (b *Builder[K, V]) Loading( loader func(ctx context.Context, key K) (Loaded[V], error), ) *LoadingBuilder[K, V]
Add loading function and switch to LoadingBuilder.
func (*Builder[K, V]) RemovalListener ¶ added in v0.2.0
func (b *Builder[K, V]) RemovalListener(listener func(key K, value V, reason RemoveReason)) *Builder[K, V]
RemovalListener adds remove callback function to builder. This function is called when entry in cache is evicted/expired/deleted.
func (*Builder[K, V]) StringKey ¶ added in v0.3.2
StringKey add a custom key -> string method, the string will be used in shard hashing.
func (*Builder[K, V]) UseEntryPool ¶ added in v0.6.0
UseEntryPool enables/disables reusing evicted entries through a sync pool. This can significantly reduce memory allocation under heavy concurrent writes, but it may lead to occasional race conditions. Theine updates its policy asynchronously, so when an Update event is processed, the corresponding entry might have already been reused. Theine will compare the key again, but this does not completely eliminate the risk of a race.
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
func (*Cache[K, V]) Close ¶
func (c *Cache[K, V]) Close()
Close closes all goroutines created by cache.
func (*Cache[K, V]) EstimatedSize ¶ added in v0.4.1
EstimatedSize returns an approximate used size of the cache.
func (*Cache[K, V]) Range ¶ added in v0.2.4
Range calls f sequentially for each key and value present in the cache. If f returns false, range stops the iteration.
func (*Cache[K, V]) SetWithTTL ¶
Set inserts or updates entry in cache with given ttl. Return false when cost > max size.
type HybridBuilder ¶ added in v0.3.0
type HybridBuilder[K comparable, V any] struct { // contains filtered or unexported fields }
func (*HybridBuilder[K, V]) AdmProbability ¶ added in v0.3.0
func (b *HybridBuilder[K, V]) AdmProbability(p float32) *HybridBuilder[K, V]
Set acceptance probability. The value has to be in the range of [0, 1].
func (*HybridBuilder[K, V]) Build ¶ added in v0.3.0
func (b *HybridBuilder[K, V]) Build() (*HybridCache[K, V], error)
Build builds a cache client from builder.
func (*HybridBuilder[K, V]) Loading ¶ added in v0.3.0
func (b *HybridBuilder[K, V]) Loading( loader func(ctx context.Context, key K) (Loaded[V], error), ) *HybridLoadingBuilder[K, V]
Add loading function and switch to HybridLoadingBuilder.
func (*HybridBuilder[K, V]) Workers ¶ added in v0.3.0
func (b *HybridBuilder[K, V]) Workers(w int) *HybridBuilder[K, V]
Set secondary cache workers. Worker will send evicted entries to secondary cache.
type HybridCache ¶ added in v0.3.0
type HybridCache[K comparable, V any] struct { // contains filtered or unexported fields }
func (*HybridCache[K, V]) Close ¶ added in v0.3.0
func (c *HybridCache[K, V]) Close()
Close closes all goroutines created by cache.
func (*HybridCache[K, V]) Delete ¶ added in v0.3.0
func (c *HybridCache[K, V]) Delete(key K) error
Delete deletes key from cache.
func (*HybridCache[K, V]) Get ¶ added in v0.3.0
func (c *HybridCache[K, V]) Get(key K) (V, bool, error)
Get gets value by key.
func (*HybridCache[K, V]) LoadCache ¶ added in v0.3.1
func (c *HybridCache[K, V]) LoadCache(version uint64, reader io.Reader) error
LoadCache load cache data from reader.
func (*HybridCache[K, V]) SaveCache ¶ added in v0.3.1
func (c *HybridCache[K, V]) SaveCache(version uint64, writer io.Writer) error
SaveCache save cache data to writer.
func (*HybridCache[K, V]) Set ¶ added in v0.3.0
func (c *HybridCache[K, V]) Set(key K, value V, cost int64) bool
Set inserts or updates entry in cache. Return false when cost > max size.
func (*HybridCache[K, V]) SetWithTTL ¶ added in v0.3.0
func (c *HybridCache[K, V]) SetWithTTL(key K, value V, cost int64, ttl time.Duration) bool
Set inserts or updates entry in cache with given ttl. Return false when cost > max size.
type HybridLoadingBuilder ¶ added in v0.3.0
type HybridLoadingBuilder[K comparable, V any] struct { // contains filtered or unexported fields }
func (*HybridLoadingBuilder[K, V]) Build ¶ added in v0.3.0
func (b *HybridLoadingBuilder[K, V]) Build() (*HybridLoadingCache[K, V], error)
Build builds a cache client from builder.
type HybridLoadingCache ¶ added in v0.3.0
type HybridLoadingCache[K comparable, V any] struct { // contains filtered or unexported fields }
func (*HybridLoadingCache[K, V]) Close ¶ added in v0.3.0
func (c *HybridLoadingCache[K, V]) Close()
Close closes all goroutines created by cache.
func (*HybridLoadingCache[K, V]) Delete ¶ added in v0.3.0
func (c *HybridLoadingCache[K, V]) Delete(key K) error
Delete deletes key from cache.
func (*HybridLoadingCache[K, V]) Get ¶ added in v0.3.0
func (c *HybridLoadingCache[K, V]) Get(ctx context.Context, key K) (V, error)
Get gets value by key.
func (*HybridLoadingCache[K, V]) LoadCache ¶ added in v0.3.0
func (c *HybridLoadingCache[K, V]) LoadCache(version uint64, reader io.Reader) error
LoadCache load cache data from reader.
func (*HybridLoadingCache[K, V]) SaveCache ¶ added in v0.3.0
func (c *HybridLoadingCache[K, V]) SaveCache(version uint64, writer io.Writer) error
SaveCache save cache data to writer.
func (*HybridLoadingCache[K, V]) Set ¶ added in v0.3.0
func (c *HybridLoadingCache[K, V]) Set(key K, value V, cost int64) bool
Set inserts or updates entry in cache. Return false when cost > max size.
func (*HybridLoadingCache[K, V]) SetWithTTL ¶ added in v0.3.0
func (c *HybridLoadingCache[K, V]) SetWithTTL(key K, value V, cost int64, ttl time.Duration) bool
Set inserts or updates entry in cache with given ttl. Return false when cost > max size.
type LoadingBuilder ¶ added in v0.3.0
type LoadingBuilder[K comparable, V any] struct { // contains filtered or unexported fields }
func (*LoadingBuilder[K, V]) Build ¶ added in v0.3.0
func (b *LoadingBuilder[K, V]) Build() (*LoadingCache[K, V], error)
Build builds a cache client from builder.
func (*LoadingBuilder[K, V]) Hybrid ¶ added in v0.3.0
func (b *LoadingBuilder[K, V]) Hybrid(cache internal.SecondaryCache[K, V]) *HybridLoadingBuilder[K, V]
Add secondary cache and switch to HybridLoadingBuilder.
type LoadingCache ¶ added in v0.2.0
type LoadingCache[K comparable, V any] struct { // contains filtered or unexported fields }
func (*LoadingCache[K, V]) Close ¶ added in v0.2.0
func (c *LoadingCache[K, V]) Close()
Close closes all goroutines created by cache.
func (*LoadingCache[K, V]) Delete ¶ added in v0.2.0
func (c *LoadingCache[K, V]) Delete(key K)
Delete deletes key from cache.
func (*LoadingCache[K, V]) EstimatedSize ¶ added in v0.4.1
func (c *LoadingCache[K, V]) EstimatedSize() int
EstimatedSize returns an approximate used size of the cache.
func (*LoadingCache[K, V]) Get ¶ added in v0.2.0
func (c *LoadingCache[K, V]) Get(ctx context.Context, key K) (V, error)
Get gets value by key.
func (*LoadingCache[K, V]) Len ¶ added in v0.2.0
func (c *LoadingCache[K, V]) Len() int
Len returns number of entries in cache.
func (*LoadingCache[K, V]) LoadCache ¶ added in v0.2.6
func (c *LoadingCache[K, V]) LoadCache(version uint64, reader io.Reader) error
LoadCache load cache data from reader.
func (*LoadingCache[K, V]) Range ¶ added in v0.2.4
func (c *LoadingCache[K, V]) Range(f func(key K, value V) bool)
Range calls f sequentially for each key and value present in the cache. If f returns false, range stops the iteration.
func (*LoadingCache[K, V]) SaveCache ¶ added in v0.2.6
func (c *LoadingCache[K, V]) SaveCache(version uint64, writer io.Writer) error
SaveCache save cache data to writer.
func (*LoadingCache[K, V]) Set ¶ added in v0.2.0
func (c *LoadingCache[K, V]) Set(key K, value V, cost int64) bool
Set inserts or updates entry in cache. Return false when cost > max size.
func (*LoadingCache[K, V]) SetWithTTL ¶ added in v0.2.0
func (c *LoadingCache[K, V]) SetWithTTL(key K, value V, cost int64, ttl time.Duration) bool
Set inserts or updates entry in cache with given ttl. Return false when cost > max size.
func (*LoadingCache[K, V]) Stats ¶ added in v0.4.1
func (c *LoadingCache[K, V]) Stats() Stats
Get cache stats.
func (*LoadingCache[K, V]) Wait ¶ added in v0.6.0
func (c *LoadingCache[K, V]) Wait()
Wait write buffer sync to policy.
type RemoveReason ¶ added in v0.1.2
type RemoveReason = internal.RemoveReason
type Serializer ¶ added in v0.3.0
type Serializer[T any] interface { internal.Serializer[T] }