Support namespacing in cache.Store implementations

Support namespacing in cache.Store by framing the interface functions
around interface{} and providing a key function to each Store implementation.

Implementation of a fix for #2294.
This commit is contained in:
Dan Mace
2015-01-26 16:44:53 -05:00
parent 35d59e6219
commit 5ee943d683
17 changed files with 385 additions and 236 deletions

View File

@@ -27,7 +27,7 @@ import (
// one object at a time.
type Enumerator interface {
Len() int
Get(index int) (ID string, object interface{})
Get(index int) (object interface{})
}
// GetFunc should return an enumerator that you wish the Poller to proccess.
@@ -76,14 +76,11 @@ func (p *Poller) run() {
}
func (p *Poller) sync(e Enumerator) {
current := p.store.ContainedIDs()
items := []interface{}{}
for i := 0; i < e.Len(); i++ {
id, object := e.Get(i)
p.store.Update(id, object)
current.Delete(id)
}
// Delete all the objects not found.
for id := range current {
p.store.Delete(id)
object := e.Get(i)
items = append(items, object)
}
p.store.Replace(items)
}