Revision 62427ee0
Von Christian Ehringfeld vor mehr als 10 Jahren hinzugefügt
| src/cache.cpp | ||
|---|---|---|
|
return false;
|
||
|
}
|
||
|
|
||
|
void Cache::insert(const QSharedPointer<Entity> &entity) {
|
||
|
void Cache::insert(QSharedPointer<Entity> &entity) {
|
||
|
if (entity.data() && entity.data()->getId() > -1) {
|
||
|
QString key = this->generateKey(entity.data()->getId(),
|
||
|
QString(entity.data()->getClassname()));
|
||
|
// if(this->cache.contains(key)) {
|
||
|
// Entity* ptr = this->cache.value(key).toStrongRef().data();
|
||
|
// Entity* refreshed = entity.data();
|
||
|
// *ptr = *refreshed;
|
||
|
// } else {
|
||
|
this->cache.insert(key,entity.toWeakRef());
|
||
|
//}
|
||
|
if (this->cache.contains(key)) {
|
||
|
QSharedPointer<Entity> ptr = this->cache.value(key).toStrongRef();
|
||
|
if (!ptr.isNull()) {
|
||
|
ptr.reset(entity.data());
|
||
|
entity = ptr;
|
||
|
}
|
||
|
}
|
||
|
this->cache.insert(key, entity.toWeakRef());
|
||
|
}
|
||
|
}
|
||
|
|
||
| src/cache.h | ||
|---|---|---|
|
}
|
||
|
return ok;
|
||
|
}
|
||
|
void insert(const QSharedPointer<Entity> &entity);
|
||
|
void insert(QSharedPointer<Entity> &entity);
|
||
|
void remove(const QSharedPointer<Entity> &entity);
|
||
|
void remove(const qint64 &id, const QString &classname);
|
||
|
template<class T> void remove(qint64 id) {
|
||
Auch abrufbar als: Unified diff
i hope this is enough to provide safe caching