...

Package vault

import "github.com/Diarkis/diarkis/vault"
Overview
Index

Overview ▾

func OnEmpty

func OnEmpty(cb func())

OnEmpty registers a callback to be invoked when all vaults are empty before shutting down

func SetShutdownWaitTime

func SetShutdownWaitTime(waitTime int)

SetShutdownWaitTime sets shutdown wait time on process termination in seconds

func Setup

func Setup()

Setup Sets up vault

func Stop

func Stop(next func(error))

Stop Stops vault

type Storage

Storage storage of each vault

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

func NewVault

func NewVault(name string, interval int64) *Storage

NewVault Creates a new vault with a name

IMPORTANT: create all required vaults BEFORE process start.
interval is in seconds

func (*Storage) AsyncGet

func (vs *Storage) AsyncGet(key string, operation func(interface{}, func()))

AsyncGet passes the vaule data to operation callback function if the key exists. This function LOCKS the vault data UNTIL operation callback calls the end callback.

func (*Storage) Clear

func (vs *Storage) Clear(vaultName string)

Clear Deletes all keys and values in the vault Does trigger OnDel

func (*Storage) Del

func (vs *Storage) Del(key string) bool

Del Deletes a key in a vault by name

func (*Storage) DelIf

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

func (*Storage) DisableStatic

func (vs *Storage) DisableStatic(key string) bool

DisableStatic makes the value of the given key not static (non-static keys will expire)

func (*Storage) EnableStatic

func (vs *Storage) EnableStatic(key string) bool

EnableStatic makes the value of the given key static (static keys do not expire)

func (*Storage) Exists

func (vs *Storage) Exists(key string) bool

Exists returns true if the given key exists - this does NOT update TTL of the key

func (*Storage) Extend

func (vs *Storage) Extend(key string, ttl int64) bool

Extend Extends TTL of a value data in a vault it allows expired vault to be extended also. ttl is in seconds.

func (*Storage) Get

func (vs *Storage) Get(key string) interface{}

Get Returns a value of a key by vault name

func (*Storage) GetAll

func (vs *Storage) GetAll() []interface{}

GetAll returns all items in the storage as an array

func (*Storage) GetAllKeys

func (vs *Storage) GetAllKeys() []string

GetAllKeys returns all keys in the storage as an array

func (*Storage) IsEmpty

func (vs *Storage) IsEmpty() bool

IsEmpty returns true if the vault is empty - it checks TTL on each item thus very slow and expensive

func (*Storage) Length

func (vs *Storage) Length() int

Length returns the number of keys in the Storage

func (*Storage) OnDel

func (vs *Storage) OnDel(callback func(string, interface{}))

OnDel Registers a callback function to a vault on delete. The callback will be passed the key and the value that has been deleted

func (*Storage) Peek

func (vs *Storage) Peek(key string) interface{}

Peek returns the stored value of the key if exists. This does NOT update the key's TTL unlike Get.

func (*Storage) Set

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

func (*Storage) SetAsStatic

func (vs *Storage) SetAsStatic(key string, values interface{}) bool

SetAsStatic sets a static key that will NEVER be discarded

IMPORTANT A static key will NEVER be discarded from the server memory

IMPORTANT A static key may sill be deleted by using Del()

func (*Storage) SetOrUpdate

func (vs *Storage) SetOrUpdate(key string, operation func(interface{}) interface{}, ttlDuration int64, isStatic bool) bool

SetOrUpdate checks to see if the key given exists.

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 (*Storage) Update

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