While it is easy to use BelongsTo relations, it might introduce to many reloading of the same entries from the database, for instance
struct A
{
int pk;
std::string something;
};
struct B
{
int pk;
BelongsTo<&A::pk> a
};
and then we want to loop over vector<B> and do something with the connected A
for(const auto& b: vector_of_B)
b.a->something; // will trigger lazy loading of the A record
now imagine that in the database we have only few records in A, but thousands in B, we should provide a way to load only once the records from the A table.
Proposal:
Implement scoping caching
struct Logic
{
DataMapperCaching _cache; // data member that is holding cache of loaded records
void foo();
};
Logic::foo()
{
DataMapperCaching cache {_cache}; // _cache is the data member and DataMapperCaching populates missing entries on destructor
for(const auto& b: vector_of_B)
b.a->something; // will trigger lazy loading of the A record if it does not exist in the cache
}
We should figure out what is the good type erasure mechanism here and also, maybe in some use cases you want to restrict caching only for one table, for instance DataMapperCaching<A> should cache only A records
While it is easy to use
BelongsTorelations, it might introduce to many reloading of the same entries from the database, for instanceand then we want to loop over
vector<B>and do something with the connectedAnow imagine that in the database we have only few records in A, but thousands in B, we should provide a way to load only once the records from the
Atable.Proposal:
Implement scoping caching
We should figure out what is the good type erasure mechanism here and also, maybe in some use cases you want to restrict caching only for one table, for instance
DataMapperCaching<A>should cache onlyArecords