cache

package
v0.0.0-...-9f7285a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyChain = errors.New("empty chain")
View Source
var ErrNotFoundInStorageErr = errors.New("not found in storage")

Functions

func NewLRUCacheItemReleaseStrategy

func NewLRUCacheItemReleaseStrategy(capacity int) *lruCacheItemReleaseStrategy

Types

type BasicCacheImpl

type BasicCacheImpl[T any] struct {
	// contains filtered or unexported fields
}

func (*BasicCacheImpl[T]) Get

func (c *BasicCacheImpl[T]) Get(key string) (T, error)

Get the instance. It retrives the data from the storage interface when it's not available in the cache.

func (*BasicCacheImpl[T]) SetAsync

func (c *BasicCacheImpl[T]) SetAsync(key string, value []byte)

type Cache

type Cache[T any] interface {
	// Get returns the associated data with converting to T
	Get(key string) (T, error)
	// SetAsync store the given cache data with the associated key in async.
	SetAsync(key string, value []byte)
}

func NewCache

func NewCache[T any](storage CacheItemStorageProvider, resolver CacheItemConverter[T], itemReleaseStrategy CacheItemReleaseStrategy) Cache[T]

type CacheItemConverter

type CacheItemConverter[T any] interface {
	Deserialize(source []byte) (T, error)
	Serialize(item T) ([]byte, error)
	Default() T
}

type CacheItemReleaseStrategy

type CacheItemReleaseStrategy interface {
	TouchAndGetRemovedKey(key string) (removedKey string)
}

type CacheItemReleaseStrategyGenerator

type CacheItemReleaseStrategyGenerator = func() CacheItemReleaseStrategy

type CacheItemStorageProvider

type CacheItemStorageProvider interface {
	Get(key string) ([]byte, error)
	Set(key string, value []byte) error
}

type GZipCacheItemStorageProvider

type GZipCacheItemStorageProvider struct {
	// contains filtered or unexported fields
}

func (*GZipCacheItemStorageProvider) Get

func (g *GZipCacheItemStorageProvider) Get(key string) ([]byte, error)

Get implements CacheItemStorageProvider.

func (*GZipCacheItemStorageProvider) Set

func (g *GZipCacheItemStorageProvider) Set(key string, value []byte) error

Set implements CacheItemStorageProvider.

type ShardingCache

type ShardingCache[T any] struct {
	// contains filtered or unexported fields
}

func NewShardingCache

func NewShardingCache[T any](storageGenerator StorageProviderGenerator, resolver CacheItemConverter[T], itemReleaseStrategyGenerator CacheItemReleaseStrategyGenerator, shardingProvider common.MapShardingProvider) *ShardingCache[T]

func (*ShardingCache[T]) Get

func (s *ShardingCache[T]) Get(key string) (T, error)

Get implements Cache.

func (*ShardingCache[T]) SetAsync

func (s *ShardingCache[T]) SetAsync(key string, value []byte)

Set implements Cache.

type ShardingMapStorageProvider

type ShardingMapStorageProvider struct {
	// contains filtered or unexported fields
}

func NewShardingMapStorageProvider

func NewShardingMapStorageProvider(shardingProvider common.MapShardingProvider) *ShardingMapStorageProvider

func (*ShardingMapStorageProvider) Get

func (s *ShardingMapStorageProvider) Get(key string) ([]byte, error)

Get implements CacheItemStorageProvider.

func (*ShardingMapStorageProvider) Set

func (s *ShardingMapStorageProvider) Set(key string, value []byte) error

Set implements CacheItemStorageProvider.

type StorageProviderGenerator

type StorageProviderGenerator = func() CacheItemStorageProvider

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL