diff --git a/FinalCommander.go b/FinalCommander.go index 1db08ab..575d39c 100644 --- a/FinalCommander.go +++ b/FinalCommander.go @@ -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 diff --git a/content/database.go b/content/database.go index 0e63baf..3198cb8 100644 --- a/content/database.go +++ b/content/database.go @@ -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 {