31 Preventing Eviction
Applications have a mechanism for preventing the DGS from evicting particular nodes (for example a GUI widget that is active within a window). This might be important because they represent transient state that cannot be calculated from the persistent models. For example a widget may record a scroll bar position.
Before evicting an independent or dependent node, the DGS evictor calls IsEvictable()
virtual bool IsEvictable() const = 0;
If this return false then the node is not evicted. It is instead moved to the back of the eviction queue.
The xc++ lamguage supports evictable{...} blocks on $dep variables which provide the implementation of IsEvictable() on that node. For example:
$dep void selfCleaningAgent_
evictable { return false; }
invalidate { PostTaskToCleanAgent(); }
calc { CalcAgent(); };
If an evictable{...} block isn't specified on a $dep then an implementation of IsEvictable() is generated which calls CacheValueIsEvictable() on the dependent variable.
$cache functions cannot define an 'evictable' block. Instead they can specialise/overload the function CacheValueIsEvictable for the mapped value type. The default implementation returns true:
template <typename T>
bool CacheValueIsEvictable(const T&)
{
// By default we assume cached values in maps are evictable.
return true;
}
The CedaGui IView system provides an overload as follows:
$interface+ IView : IObject
{
bool IsEvictable() const;
...
};
inline bool CacheValueIsEvictable(ptr<IView> v)
{
return v ? v->IsEvictable() : true;
}