Commit 2e8448ad authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb: Don't expose LiveCache internal organization onto its users

Provide functions to:

- set cache element
- iterate through all elements

LiveCache organization will be changed in the following patch, and it is
better to keep the knowledge about its internal structure localized.
parent 6badef15
...@@ -179,6 +179,22 @@ func (cache *LiveCache) Get(oid Oid) IPersistent { ...@@ -179,6 +179,22 @@ func (cache *LiveCache) Get(oid Oid) IPersistent {
return obj return obj
} }
// setNew sets objects corresponding to oid.
//
// The cache must not have entry for oid when setNew is called.
func (cache *LiveCache) setNew(oid Oid, obj IPersistent) {
cache.objtab[oid] = weak.NewRef(obj)
}
// forEach calls f for all objects in the cache.
func (cache *LiveCache) forEach(f func(IPersistent)) {
for _, wobj := range cache.objtab {
if xobj := wobj.Get(); xobj != nil {
f(xobj.(IPersistent))
}
}
}
// SetControl installs c to handle cache decisions. // SetControl installs c to handle cache decisions.
// //
// Any previously installed cache control is uninstalled. // Any previously installed cache control is uninstalled.
...@@ -199,7 +215,7 @@ func (conn *Connection) get(class string, oid Oid) (IPersistent, error) { ...@@ -199,7 +215,7 @@ func (conn *Connection) get(class string, oid Oid) (IPersistent, error) {
obj := conn.cache.Get(oid) obj := conn.cache.Get(oid)
if obj == nil { if obj == nil {
obj = newGhost(class, oid, conn) obj = newGhost(class, oid, conn)
conn.cache.objtab[oid] = weak.NewRef(obj) conn.cache.setNew(oid, obj)
checkClass = false checkClass = false
} }
conn.cache.Unlock() conn.cache.Unlock()
......
...@@ -565,14 +565,9 @@ func (conn *Connection) resync1(at Tid) { ...@@ -565,14 +565,9 @@ func (conn *Connection) resync1(at Tid) {
defer conn.cache.Unlock() defer conn.cache.Unlock()
if δall { if δall {
// XXX keep synced with LiveCache details conn.cache.forEach(func(obj IPersistent) {
// XXX -> conn.cache.forEach?
for _, wobj := range conn.cache.objtab {
obj, _ := wobj.Get().(IPersistent)
if obj != nil {
obj.PInvalidate() obj.PInvalidate()
} })
}
} else { } else {
for oid := range δobj { for oid := range δobj {
obj := conn.cache.Get(oid) obj := conn.cache.Get(oid)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment