30 OnEvict handler

When a node is evicted (either independent or dependent), the virtual function OnEvict() is called.

Eviction takes care of removing both dependent and independent nodes in maps that haven't been used for a long time.

A $dep can define a handler for its eviction with an evict{...} block:


$dep int y
    evict      { }
    invalidate { }
    calc       { };

If no evict{...} block is specified then Xcpp instead generates an OnEvict handler which calls OnEvictCacheValue() on the dependent variable.

The default implementation of OnEvictCacheValue() is a no-op:


template <typename T>
void OnEvictCacheValue(const T&)
{
}

$cache functions similarly support eviction handling by generating an OnEvict handler which calls OnEvictCacheValue() on the mapped variable.

A $cache function that takes zero input arguments calls ClearCacheValue() on the mapped variable after calling OnEvictCacheValue() on the mapped variable.

The default implementation of ClearCacheValue uses template specialisation to clear a ptr<T> variable.


template <typename T>
void ClearCacheValue(T&)
{
}

template <typename T>
void ClearCacheValue(ptr<T>& v)
{
    v = null;
}