mirror of https://github.com/perkeep/perkeep.git
sorted: make the in-memory implementation support Wiper
So an in-memory key/value store can be used as an index, for the demo blob server on the website.
This commit is contained in:
parent
4fa9c80be0
commit
e29e6dc98c
|
@ -31,10 +31,13 @@ import (
|
|||
// NewMemoryKeyValue returns a KeyValue implementation that's backed only
|
||||
// by memory. It's mostly useful for tests and development.
|
||||
func NewMemoryKeyValue() KeyValue {
|
||||
db := memdb.New(comparer.DefaultComparer, 128)
|
||||
return &memKeys{db: db}
|
||||
kv := new(memKeys)
|
||||
kv.Wipe()
|
||||
return kv
|
||||
}
|
||||
|
||||
var _ Wiper = (*memKeys)(nil)
|
||||
|
||||
// memKeys is a naive in-memory implementation of KeyValue for test & development
|
||||
// purposes only.
|
||||
type memKeys struct {
|
||||
|
@ -42,6 +45,13 @@ type memKeys struct {
|
|||
db *memdb.DB
|
||||
}
|
||||
|
||||
func (s *memKeys) Wipe() error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.db = memdb.New(comparer.DefaultComparer, 128)
|
||||
return nil
|
||||
}
|
||||
|
||||
// memIter converts from leveldb's iterator.Iterator interface, which
|
||||
// operates on []byte, to Perkeep's index.Iterator, which operates
|
||||
// on string.
|
||||
|
|
Loading…
Reference in New Issue