浏览代码

fix : synchronize fields after locking an unlocked cached object

Nicolas Cannasse 16 年之前
父节点
当前提交
1154aeca9f
共有 2 个文件被更改,包括 11 次插入2 次删除
  1. 1 0
      doc/CHANGES.txt
  2. 10 2
      std/neko/db/Manager.hx

+ 1 - 0
doc/CHANGES.txt

@@ -33,6 +33,7 @@ TODO :
 	compiler : allowed \r line separators for HXML files
 	flash9 : fixed verify error with loop variable beeing a specific class
 	compiler : prevent truncating float dynamic values to int when using numerical operations
+	neko.db.Manager fix : synchronize fields after locking an unlocked cached object
 
 2008-11-23: 2.02
 	Std.is(MyInterface, Class) now returns true (haXe/PHP)

+ 10 - 2
std/neko/db/Manager.hx

@@ -511,9 +511,17 @@ class Manager<T : Object> {
 
 	function getFromCache( x : T, lock : Bool ) : T {
 		var c : Dynamic = object_cache.get(makeCacheKey(x));
-		// restore update method since now the object is locked
-		if( c != null && lock && c.update == no_update )
+		if( c != null && lock && c.update == no_update ) {
+			// restore update method since now the object is locked
 			c.update = class_proto.prototype.update;
+			// and synchronize the fields since our result is up-to-date !
+			for( f in Reflect.fields(c) )
+				Reflect.deleteField(c,f);
+			for( f in Reflect.fields(x) )
+				Reflect.setField(c,f,Reflect.field(x,f));
+			// use the new object as our cache of fields
+			Reflect.setField(c,cache_field,x);
+		}
 		return c;
 	}