func OnEmpty(cb func())
OnEmpty registers a callback to be invoked when all vaults are empty before shutting down
func SetShutdownWaitTime(waitTime int)
SetShutdownWaitTime sets shutdown wait time on process termination in seconds
func Setup()
Setup Sets up vault
func Stop(next func(error))
Stop Stops vault
Storage storage of each vault
type Storage struct {
// contains filtered or unexported fields
}
func NewVault(name string, interval int64) *Storage
NewVault Creates a new vault with a name
[NOTE] Uses mutex lock internall.
IMPORTANT: create all required vaults BEFORE process start. interval is in seconds
func (vs *Storage) AsyncGet(key string, operation func(interface{}, func()))
AsyncGet passes the vaule data to operation callback function if the key exists.
[NOTE] Uses mutex lock internall.
This function LOCKS the vault data UNTIL operation callback calls the end callback.
func (vs *Storage) Clear(vaultName string)
Clear Deletes all keys and values in the vault
[NOTE] Uses mutex lock internall.
Does trigger OnDel
func (vs *Storage) Del(key string) bool
Del Deletes a key in a vault by name
[NOTE] Uses mutex lock internall.
func (vs *Storage) DelIf(key string, condition func(val interface{}) bool) bool
DelIf deletes the value of the key given if the conditions implemented by condition function are met
[NOTE] Uses mutex lock internall.
func (vs *Storage) DisableStatic(key string) bool
DisableStatic makes the value of the given key not static (non-static keys will expire)
[NOTE] Uses mutex lock internall.
func (vs *Storage) EnableStatic(key string) bool
EnableStatic makes the value of the given key static (static keys do not expire)
[NOTE] Uses mutex lock internall.
func (vs *Storage) Exists(key string) bool
Exists returns true if the given key exists - this does NOT update TTL of the key
[NOTE] Uses mutex lock internall.
func (vs *Storage) Extend(key string, ttl int64) bool
Extend Extends TTL of a value data in a vault
[NOTE] Uses mutex lock internall.
it allows expired vault to be extended also. ttl is in seconds.
func (vs *Storage) Get(key string) interface{}
Get Returns a value of a key by vault name
[NOTE] Uses mutex lock internall.
func (vs *Storage) GetAll() []interface{}
GetAll returns all items in the storage as an array
[NOTE] Uses mutex lock internall.
func (vs *Storage) GetAllKeys() []string
GetAllKeys returns all keys in the storage as an array
[NOTE] Uses mutex lock internall.
func (vs *Storage) IsEmpty() bool
IsEmpty returns true if the vault is empty - it checks TTL on each item thus very slow and expensive
[NOTE] Uses mutex lock internall.
func (vs *Storage) Length() int
Length returns the number of keys in the Storage
[NOTE] Uses mutex lock internall.
func (vs *Storage) OnDel(callback func(string, interface{}))
OnDel Registers a callback function to a vault on delete.
[NOTE] Uses mutex lock internall.
The callback will be passed the key and the value that has been deleted
func (vs *Storage) Peek(key string) interface{}
Peek returns the stored value of the key if exists.
[NOTE] Uses mutex lock internall.
This does NOT update the key's TTL unlike Get.
func (vs *Storage) Set(key string, values interface{}, ttlDuration int64) bool
Set Sets a vaul of a key by vault name - ttlDuration is in seconds
[NOTE] Uses mutex lock internall.
func (vs *Storage) SetAsStatic(key string, values interface{}) bool
SetAsStatic sets a static key that will NEVER be discarded
[NOTE] Uses mutex lock internall.
IMPORTANT A static key may sill be deleted by using Del()
func (vs *Storage) SetOrUpdate(key string, operation func(interface{}) interface{}, ttlDuration int64, isStatic bool) bool
SetOrUpdate checks to see if the key given exists.
[NOTE] Uses mutex lock internall.
If the key does not exist or has expired, it creates a new entry by using the returned value interface{} from operation function. If key exists and it is valid, it allows operation function to update the entry passed to it. If isStatic is true, the item will NEVER be discarded
func (vs *Storage) Update(key string, operation func(interface{})) interface{}
Update Updates a value of a key by vault name and returns the updated data
[NOTE] Uses mutex lock internall.