Documentation
¶
Index ¶
Constants ¶
const ( DefaultDBPath = ".e-dnevnik.db" // default BadgerDB folder DefaultTTL = time.Hour * 9000 // a bit more than 1 year TTL DefaultDiscardRatio = 0.5 // recommended discard ratio from Badger docs )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Edb ¶
type Edb struct {
// contains filtered or unexported fields
}
Edb holds e-dnevnik structure including Bardger struct.
func (*Edb) CheckAndFlagTTL ¶ added in v0.20.0
CheckAndFlagTTL checks if a key already exists in the database and marks it with a flag if it doesn't exist. The flag is set with a TTL of 1+ year.
The key is created by hashing a concatenation of the bucket, subBucket and target strings using SHA-256.
If the key already exists, the function returns (true, nil). If the key doesn't exist, the function marks the key and returns (false, nil) on success or (false, error) on error.
func (*Edb) Close ¶
Close closes database, optionally running GC (removing state data from value log file).
func (*Edb) FetchAndStore ¶ added in v0.20.0
FetchAndStore fetches a value by key, applies a given function to the value and stores the result.
It does the following steps:
1. Finds the key in the database. 2. Copies the associated value. 3. Calls the given function with the copied value as argument and stores the result. 4. Stores the result in the database with the same key and a TTL of 1+ year.
If any of the steps fail, it will return an error.