Add key removal
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2022-01-20 00:37:15 +01:00
parent 7573e47b77
commit 525e11eb6a
2 changed files with 14 additions and 0 deletions

View file

@ -129,6 +129,7 @@ func handle(ctx *httputils.RequestContext) {
if len(pathElements) > 3 {
if pathElements[3] == "information" {
ctx.SetResponseCode(http.StatusOK)
ctx.SetResponseHeader("Content-Type", "application/json")
if entry != nil {
b, _ := json.Marshal(struct {
@ -158,6 +159,13 @@ func handle(ctx *httputils.RequestContext) {
ctx.ServeBytes(b)
}
return
} else if pathElements[3] == "drop" { //Drop key from cache
ctx.SetResponseCode(http.StatusOK)
_ = db.RemoveEntry(key)
if entry != nil && !entry.Key.Equals(key) {
_ = db.RemoveEntry(&entry.Key)
}
return
}
//TODO: update entries with these instant returns

View file

@ -53,6 +53,12 @@ func (db *Database) SetEntry(entry *Entry) error {
})
}
func (db *Database) RemoveEntry(key *HashIdentifier) error {
return db.handle.Update(func(txn *badger.Txn) error {
return txn.Delete(key.Encode())
})
}
func (db *Database) getChain(txn *badger.Txn, key HashIdentifier) (*Entry, error) {
item, err := txn.Get(key.Encode())
if err != nil {