Skip to content

Commit

Permalink
fix: hold the reference by cache util
Browse files Browse the repository at this point in the history
  • Loading branch information
seven-mile committed Sep 17, 2023
1 parent 74d5528 commit 32c788c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions UFCase/CacheUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,28 @@ namespace winrt::UFCase
ClassT &self;
MemberT prop;

inline static ClassCacheStore<ClassT> store;
inline static std::shared_ptr<ClassCacheStore<ClassT>> store;

public:
PropertyCache(ClassT &self, MemberT prop) : self(self), prop(prop)
{
store = ClassCacheStore<ClassT>::GetStrong();
}
~PropertyCache()
{
ClassCacheStore<ClassT>::GetStrong()->Invalidate(&self, prop);
store->Invalidate(&self, prop);
}

RetT operator()()
{
if (auto val = ClassCacheStore<ClassT>::GetStrong()->Get(&self, prop); val.has_value())
if (auto val = store->Get(&self, prop); val.has_value())
{
return *val;
}
else
{
auto new_val = (self.*prop)();
ClassCacheStore<ClassT>::GetStrong()->Set(&self, prop, new_val);
store->Set(&self, prop, new_val);
return new_val;
}
}
Expand Down

0 comments on commit 32c788c

Please sign in to comment.