Package data contains basic threadsafe data structures with filesystem persistance and configurable flushing policies.
FlushPolicy is the type of flush policy to use.
const ( // FlushOnEdit saves the object to disk after every modification. FlushOnEdit FlushPolicy = iota // FlushExplicit saves the object to disk only if the Flush method of // the object is explicitly called. FlushExplicit // FlushNone never saves the object to disk. FlushNone )
UnsortedKV is a thread safe and unsorted key-value storage with optional persistency on disk.
NewDiskUnsortedKV returns an UnsortedKV that flushed data on disk every time it gets updated.
NewDiskUnsortedKVReader returns an UnsortedKV from disk as a reader but it doesn't flush any modifications on disk.
NewMemUnsortedKV returns an UnsortedKV that only lives in memory and never persists on disk.
NewUnsortedKV creates a new UnsortedKV with the given flush policy. If fileName already exists, it will be deserialized and loaded.
Clear deletes every named object from the store.
Del deletes a named object from the store.
Each iterates each named object in the store by executing the callback cb on them, if the callback returns true the iteration is interrupted.
Empty returns bool if the store is empty.
Flush flushes the store to disk if the flush policy is different than FlushNone
Get return the value of the named object if present, or returns found as false otherwise.
GetOr will return the value of the named object if present, or a default value.
Has return true if name exists in the store.
MarshalJSON is used to serialize the UnsortedKV data structure to JSON correctly.
Set sets a value for a named object.