commit 62427ee0c716323385a914be6e7c8f4cb0d57e1a
Author: Christian Ehringfeld <c.ehringfeld@t-online.de>
Date:   Tue May 26 20:57:45 2015 +0200

    i hope this is enough to provide safe caching

diff --git a/src/cache.cpp b/src/cache.cpp
index bcb9325..6f1ba40 100644
--- a/src/cache.cpp
+++ b/src/cache.cpp
@@ -34,17 +34,18 @@ bool Cache::contains(const QString &key) {
     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());
     }
 }
 
diff --git a/src/cache.h b/src/cache.h
index c2b04f4..040d542 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -38,7 +38,7 @@ class Cache {
         }
         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) {
