Documentation ¶
Index ¶
- Constants
- type CreateOptionFunc
- func SetEnablePersistence(name string) CreateOptionFunc
- func SetExpirationTime(expiration time.Duration) CreateOptionFunc
- func SetGcInterval(gcInterval time.Duration) CreateOptionFunc
- func SetPersistencePath(path string) CreateOptionFunc
- func SetPersistencePolicy(policy Persistence) CreateOptionFunc
- type Interface
- type Item
- type Map
- func (c *Map[E]) Add(key string, value E) error
- func (c *Map[E]) Clear()
- func (c *Map[E]) Delete(key string) (E, bool)
- func (c *Map[E]) DeleteExpired()
- func (c *Map[E]) Get(key string) (E, bool)
- func (c *Map[E]) GetAndDelete(key string) (E, bool)
- func (c *Map[E]) GetAndExpired(key string) (E, bool)
- func (c *Map[E]) GetWithExpiration(key string) (E, time.Time, bool)
- func (c *Map[E]) IsExpired(key string) (bool, error)
- func (c *Map[E]) Keys() []string
- func (c *Map[E]) Set(key string, value E)
- func (c *Map[E]) SetDefault(key string, value E, expiration time.Duration)
- func (c *Map[E]) StartGc() error
- func (c *Map[E]) StopGc() error
- type MapInterface
- type Persistence
Constants ¶
const ( // DefaultExpiration Default expiration time flag, never expires DefaultExpiration time.Duration = -1 // DefaultInterval Default expiration interval is one minute DefaultInterval = time.Minute // DefaultPersistencePath default persistence path DefaultPersistencePath = "/val/cache/persistence" )
const FileSUFFIX = "_ffb.cdb"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreateOptionFunc ¶
type CreateOptionFunc func(o *options)
CreateOptionFunc Initialize optional parameters
func SetEnablePersistence ¶
func SetEnablePersistence(name string) CreateOptionFunc
SetEnablePersistence SetDefault whether to enable persistencePolicy
func SetExpirationTime ¶
func SetExpirationTime(expiration time.Duration) CreateOptionFunc
SetExpirationTime set expiration time expiration time
func SetGcInterval ¶
func SetGcInterval(gcInterval time.Duration) CreateOptionFunc
SetGcInterval set gc interval When the cleaning cycle is 0, it is automatically adjusted to 1 minute
func SetPersistencePath ¶
func SetPersistencePath(path string) CreateOptionFunc
SetPersistencePath set persistence path,default persistence path is DefaultPersistencePath
func SetPersistencePolicy ¶
func SetPersistencePolicy(policy Persistence) CreateOptionFunc
SetPersistencePolicy set persistencePolicy policy,default persistencePolicy is FFB
type Interface ¶
type Interface[E any] interface { // IsExpired judge whether the data is expired IsExpired(key string) (bool, error) // DeleteExpired delete all expired data DeleteExpired() // StartGc start gc // After the expiration time is set, GC will be started automatically without manual GC StartGc() error // StopGc stop gc StopGc() error // Get data // When the data does not exist or expires, it will return nonexistence(false) Get(key string) (E, bool) // GetAndDelete get data and delete by key GetAndDelete(key string) (E, bool) // GetAndExpired get data and expire by key // It will be deleted at the next clearing. If the clearing capability is not enabled, it will never be deleted GetAndExpired(key string) (E, bool) // GetWithExpiration get expiration time GetWithExpiration(key string) (E, time.Time, bool) // Delete delete data by key Delete(key string) (E, bool) }
type Map ¶
type Map[E any] struct { // contains filtered or unexported fields }
func (*Map[E]) DeleteExpired ¶
func (c *Map[E]) DeleteExpired()
DeleteExpired delete all expired data
func (*Map[E]) Get ¶
Get data When the data does not exist or expires, it will return nonexistence(false)
func (*Map[E]) GetAndDelete ¶
GetAndDelete get data and delete by key
func (*Map[E]) GetAndExpired ¶
GetAndExpired get data and expire by key It will be deleted at the next clearing. If the clearing capability is not enabled, it will never be deleted
func (*Map[E]) GetWithExpiration ¶
func (*Map[E]) SetDefault ¶
SetDefault data by key,it will overwrite the data if the key exists
type MapInterface ¶
type MapInterface[E any] interface { Interface[E] // Set data by key,it will overwrite the data if the key exists Set(key string, value E) // SetDefault data by key,it will overwrite the data if the key exists SetDefault(key string, value E, expiration time.Duration) // Add data,Cannot add existing data // To override the addition, use the set method Add(key string, value E) error // Clear remove all data Clear() // Keys get all keys Keys() []string }
func NewMapCache ¶
func NewMapCache[E any](opts ...CreateOptionFunc) (MapInterface[E], error)
NewMapCache create a cache with Map
type Persistence ¶
type Persistence int
Persistence policy
const ( // FFB Full File Backup FFB Persistence = iota )