Documentation
¶
Index ¶
- Constants
- type Cache
- func (c Cache) Add(k string, x any, d time.Duration) error
- func (c Cache) CacheSize() int
- func (c Cache) Decrement(k string, n int64) error
- func (c Cache) DecrementFloat(k string, n float64) error
- func (c Cache) Delete(k string)
- func (c Cache) Flush()
- func (c Cache) Get(k string) (any, bool)
- func (c Cache) GetCreateTime(k string) (time.Time, bool)
- func (c Cache) GetShardMap(key string) *SharedMap
- func (c Cache) GetUpdateTime(k string) (time.Time, bool)
- func (c Cache) GetWithExpiration(k string) (any, time.Time, bool)
- func (c Cache) Increment(k string, n int64) error
- func (c Cache) IncrementFloat(k string, n float64) error
- func (c Cache) ItemCount() (count int)
- func (c Cache) Items() map[string]Item
- func (c Cache) ItemsInit(items map[string]Item)
- func (c Cache) OnEvicted(f func(key string, value any))
- func (c Cache) OnExited(f func(), isSave bool)
- func (c Cache) RunJanitor(jt janitorType)
- func (c Cache) Set(k string, x any, d time.Duration) error
- func (c Cache) StopJanitor(jt janitorType)
- func (c Cache) UnsafeDelete(k string)
- func (c Cache) UnsafeGet(k string) (any, bool)
- func (c Cache) Update(k string, x any) error
- func (c Cache) UpdateExpiration(k string, d time.Duration) error
- type Config
- type Item
- type Janitor
- type SharedMap
Constants ¶
const ( DefaultExpiration time.Duration = 0 MaxBytes = 17179869184 // 16G ShardCount = 32 )
const ( Cleanup janitorType = "CLEANUP" Saving janitorType = "SAVING" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func NewFrom ¶
NewFrom Encapsulates the New and c.ItemInit(). You can also use them separately. Note that the items parameter needs to be generated in advance using the c.Items(). It is not recommended to pass custom items directly, as this may cause unknown errors.
func (Cache) DecrementFloat ¶
DecrementFloat for float, item.V - n.
func (Cache) Get ¶
Get return item.V, isFound. If item has expired or isDeleted is true, will not be found.
func (Cache) GetCreateTime ¶
GetCreateTime return item.CreateTime, isFound.
func (Cache) GetShardMap ¶
GetShardMap return key's SharedMap. It is not recommended to directly operate SharedMap.
func (Cache) GetUpdateTime ¶
GetUpdateTime return item.UpdateTime, isFound.
func (Cache) GetWithExpiration ¶
GetWithExpiration return item.V, item.ExpirationTime, isFound.
func (Cache) IncrementFloat ¶
IncrementFloat for float, item.V + n.
func (Cache) OnEvicted ¶
OnEvicted supports configuring the actions you want to do after Delete || UnsafeDelete || c.clean().
func (Cache) OnExited ¶
func (c Cache) OnExited(f func(), isSave bool)
OnExited supports configuring the actions you want to do when the program exits or crashes. And also supports choosing whether to export the data in the cache after your actions.
func (Cache) RunJanitor ¶
func (c Cache) RunJanitor(jt janitorType)
RunJanitor If you set CleanupInterval or SavingInterval, you do not need to call it explicitly. Of course, you can use this method to start a custom Janitor after mounting the Cache instance. Note that jt is a janitorType and needs to reference the Janitor constant(Cleanup or Saving).
func (Cache) Set ¶ added in v1.0.5
Set k key, x value, d defaultExpiration(0:Never expire). If the key exists, it will be overwritten.
func (Cache) StopJanitor ¶
func (c Cache) StopJanitor(jt janitorType)
StopJanitor If you set CleanupInterval or SavingInterval, you do not need to call it explicitly. Of course, you can use this method to stop a custom Janitor after mounting the Cache instance. Note that jt is a janitorType and needs to reference the Janitor constant(Cleanup or Saving).
func (Cache) UnsafeDelete ¶
func (c Cache) UnsafeDelete(k string)
UnsafeDelete only modifies item.IsDeleted to make it invisible.
func (Cache) UnsafeGet ¶
UnsafeGet return item.V, isExist. It will also return data that has expired and isDeleted is true.
type Config ¶
type Config struct {
ShardCount int
MaxBytes int
DefaultExpiration time.Duration
CleanupInterval time.Duration
SavingInterval time.Duration
}
Config Note that the default values of MaxBytes and ShardCount are 16G and 32, the default values of DefaultExpiration, CleanupInterval, and SavingInterval which means that the data never expire, The CleanupJanitor and SavingJanitor are not enabled by default.