refs #684, #766, #776 Support %OwnerName% in cache keys by allowing CCached::m_element to be a dummy

and by using a trick with explicit destructor call and placement new to reconstruct CCached when owner's name changes.
This commit is contained in:
Mathew Sutcliffe
2016-10-15 20:37:00 +01:00
parent 9acfb89e65
commit 8a65a33384
5 changed files with 61 additions and 5 deletions

View File

@@ -309,6 +309,11 @@ namespace BlackMisc
CData(T *owner) :
CData::CCached(CDataCache::instance(), Trait::key(), Trait::humanReadable(), Trait::isValid, Trait::defaultValue(), owner)
{
if (! this->isInitialized())
{
this->onOwnerNameChanged([this, owner] { Private::reconstruct(this, owner); });
return;
}
if (Trait::timeToLive() >= 0) { CDataCache::instance()->setTimeToLive(this->getKey(), Trait::timeToLive()); }
if (Trait::isPinned()) { CDataCache::instance()->pinValue(this->getKey()); }
if (Trait::isDeferred()) { CDataCache::instance()->deferValue(this->getKey()); }