Documentation
¶
Index ¶
- Constants
- func GetDatabaseCacheStatus[K comparable, T any](c *DataBaseCacheWithKey[K, T], key K) databaseCacheItemStatus
- func NewConfig(opts ...Option) *config
- type Cache
- type CacheItem
- type DBItem
- type DataBaseCacheWithKey
- func (c *DataBaseCacheWithKey[K, T]) Close()
- func (c *DataBaseCacheWithKey[K, T]) Count() int
- func (c *DataBaseCacheWithKey[K, T]) Delete(key K)
- func (c *DataBaseCacheWithKey[K, T]) DisableSave()
- func (c *DataBaseCacheWithKey[K, T]) EnableSave()
- func (c *DataBaseCacheWithKey[K, T]) ForEach(f func(K, T) bool)
- func (c *DataBaseCacheWithKey[K, T]) Get(key K) (T, bool)
- func (c *DataBaseCacheWithKey[K, T]) GetAll() map[K]T
- func (c *DataBaseCacheWithKey[K, T]) GetPure(key K) (T, bool)
- func (c *DataBaseCacheWithKey[K, T]) IsClose() bool
- func (c *DataBaseCacheWithKey[K, T]) IsSaveDisabled() bool
- func (c *DataBaseCacheWithKey[K, T]) Set(key K, memValue T)
- type DeleteFunc
- type Fetch
- type FetchFunc
- type LoadFromDatabase
- type LoadFunc
- type MarshalFunc
- type MemoryItem
- type Option
- type Save
- type SaveDatabase
- type SaveFunc
Constants ¶
const ( DatabaseCacheItemNormal databaseCacheItemStatus = iota // save to database before expired DatabaseCacheItemSave // expired, save to database and delete(default) or update(Update-status) DatabaseCacheItemUpdate // someone peek the instruction when save, update the instruction after save DatabaseCacheItemNotFound )
Variables ¶
This section is empty.
Functions ¶
func GetDatabaseCacheStatus ¶
func GetDatabaseCacheStatus[K comparable, T any](c *DataBaseCacheWithKey[K, T], key K) databaseCacheItemStatus
Types ¶
type Cache ¶
type Cache[T MemoryItem, D DBItem] struct { // contains filtered or unexported fields }
func NewCache ¶
func NewCache[T MemoryItem, D DBItem]( ttl time.Duration, marshal MarshalFunc[T, D], fetch FetchFunc[D], delete DeleteFunc[D], save SaveFunc[D], load LoadFunc[T, D], opt ...Option, ) *Cache[T, D]
type CacheItem ¶
type CacheItem[T MemoryItem, D DBItem] struct { MemoryItem T DBItem D }
type DataBaseCacheWithKey ¶
type DataBaseCacheWithKey[K comparable, T any] struct { // contains filtered or unexported fields }
func NewDatabaseCacheWithKey ¶
func NewDatabaseCacheWithKey[K comparable, T any]( ttl time.Duration, save SaveDatabase[K, T], load LoadFromDatabase[K, T], ) *DataBaseCacheWithKey[K, T]
param: cache : ttl/lru cache save: save to database, function should be blocking, return true is success load: load from database, function should be blocking, return data and error
func (*DataBaseCacheWithKey[K, T]) Close ¶
func (c *DataBaseCacheWithKey[K, T]) Close()
func (*DataBaseCacheWithKey[K, T]) Count ¶
func (c *DataBaseCacheWithKey[K, T]) Count() int
func (*DataBaseCacheWithKey[K, T]) Delete ¶
func (c *DataBaseCacheWithKey[K, T]) Delete(key K)
func (*DataBaseCacheWithKey[K, T]) DisableSave ¶
func (c *DataBaseCacheWithKey[K, T]) DisableSave()
DisableSave disables saving to database
func (*DataBaseCacheWithKey[K, T]) EnableSave ¶
func (c *DataBaseCacheWithKey[K, T]) EnableSave()
EnableSave enables saving to database
func (*DataBaseCacheWithKey[K, T]) ForEach ¶
func (c *DataBaseCacheWithKey[K, T]) ForEach(f func(K, T) bool)
func (*DataBaseCacheWithKey[K, T]) Get ¶
func (c *DataBaseCacheWithKey[K, T]) Get(key K) (T, bool)
func (*DataBaseCacheWithKey[K, T]) GetAll ¶
func (c *DataBaseCacheWithKey[K, T]) GetAll() map[K]T
func (*DataBaseCacheWithKey[K, T]) GetPure ¶
func (c *DataBaseCacheWithKey[K, T]) GetPure(key K) (T, bool)
func (*DataBaseCacheWithKey[K, T]) IsClose ¶
func (c *DataBaseCacheWithKey[K, T]) IsClose() bool
func (*DataBaseCacheWithKey[K, T]) IsSaveDisabled ¶
func (c *DataBaseCacheWithKey[K, T]) IsSaveDisabled() bool
IsSaveDisabled returns whether saving to database is disabled
func (*DataBaseCacheWithKey[K, T]) Set ¶
func (c *DataBaseCacheWithKey[K, T]) Set(key K, memValue T)
type DeleteFunc ¶
type DeleteFunc[D DBItem] func([]D)
type Fetch ¶
type Fetch[T any] struct { // contains filtered or unexported fields }
func NewFetchWithConfig ¶
func (*Fetch[T]) DeleteRest ¶
Close stops the background goroutine and closes the buffer channel.
type LoadFromDatabase ¶
type LoadFromDatabase[K comparable, T any] func(K) (T, error)
load data from database by key attention: this function should be blocking
type MarshalFunc ¶
type MarshalFunc[T MemoryItem, D DBItem] func(T, D)
type MemoryItem ¶
type Option ¶
type Option func(*config)
func WithContext ¶
func WithEnableSave ¶
func WithFetchSize ¶
func WithSaveSize ¶
func WithSaveTimeout ¶
type Save ¶
type Save[T any] struct { // contains filtered or unexported fields }
Save provides a way to collect items and save them in batches using a background goroutine. It buffers items and periodically passes them to a save function for processing.
func NewSave ¶
NewSave creates a new Saver with the specified buffer size and save function. It starts a background goroutine to process items from the buffer.
func NewSaveWithConfig ¶
type SaveDatabase ¶
type SaveDatabase[K comparable, T any] func(K, T, utils.EvictionReason) bool
save to database attention: this function should be blocking