Commit c67ff9ea authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb: Connection: Allow applications to tune live-cache eviction policy

For example Wendelin.core wcfs will need to keep some types of objects
(e.g. BigFile index) always in RAM for efficiency.

Provide corresponding interface that application could use to install
such live-cache eviction decision-making tuning.
parent fb343a6f
......@@ -92,6 +92,22 @@ type Connection struct {
// Hopefully we don't have cycles with BTree/Bucket.
objmu sync.Mutex
objtab map[Oid]*weak.Ref // oid -> weak.Ref(IPersistent)
// hooks for application to influence live caching decisions.
cacheControl LiveCacheControl
}
// LiveCacheControl is the interface that allows applications to influence
// Connection's decisions with respect to Connection's live cache.
type LiveCacheControl interface {
// WantEvict is called when object is going to be evicted from live
// cache on deactivation and made ghost.
//
// If !ok the object will remain live.
//
// NOTE on invalidation invalidated objects are evicted from live cache
// unconditionally.
WantEvict(obj IPersistent) (ok bool)
}
// ----------------------------------------
......
......@@ -221,6 +221,13 @@ func (obj *Persistent) PDeactivate() {
// TODO try to keep some pool of object in live state so that there is
// no constant load/unload on object access. XXX -> MRU cache?
// NOTE wcfs manages its objects explicitly and does not need this.
if cc := obj.jar.cacheControl; cc != nil {
if !cc.WantEvict(obj.instance) {
return
}
}
obj.serial = InvalidTid
obj.istate().DropState()
......
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