@@ -37,7 +37,10 @@ public IEntity GetById(Type type, Guid id)
37
37
var containsKey = _cache . ContainsKey ( compositeKey ) ;
38
38
if ( containsKey )
39
39
{
40
- return _cache [ compositeKey ] ;
40
+ var result = _cache [ compositeKey ] ;
41
+
42
+ //IMPORTANT: we must clone to resolve, see: http://issues.umbraco.org/issue/U4-4259
43
+ return ( IEntity ) result . DeepClone ( ) ;
41
44
}
42
45
43
46
return null ;
@@ -56,7 +59,12 @@ select GetCompositeId(type, id)
56
59
into key
57
60
let containsKey = _cache . ContainsKey ( key )
58
61
where containsKey
59
- select _cache [ key ] ) . ToList ( ) ;
62
+ select _cache [ key ]
63
+ into result
64
+ //don't return null objects
65
+ where result != null
66
+ //IMPORTANT: we must clone to resolve, see: http://issues.umbraco.org/issue/U4-4259
67
+ select ( IEntity ) result . DeepClone ( ) ) . ToList ( ) ;
60
68
return list ;
61
69
}
62
70
@@ -67,7 +75,14 @@ where containsKey
67
75
/// <returns></returns>
68
76
public IEnumerable < IEntity > GetAllByType ( Type type )
69
77
{
70
- var list = _cache . Keys . Where ( key => key . Contains ( type . Name ) ) . Select ( key => _cache [ key ] ) . ToList ( ) ;
78
+ var list = _cache . Keys
79
+ . Where ( key => key . Contains ( type . Name ) )
80
+ . Select ( key => _cache [ key ] )
81
+ //don't return null objects
82
+ . Where ( result => result != null )
83
+ //IMPORTANT: we must clone to resolve, see: http://issues.umbraco.org/issue/U4-4259
84
+ . Select ( result => ( IEntity ) result . DeepClone ( ) )
85
+ . ToList ( ) ;
71
86
return list ;
72
87
}
73
88
@@ -78,6 +93,9 @@ public IEnumerable<IEntity> GetAllByType(Type type)
78
93
/// <param name="entity"></param>
79
94
public void Save ( Type type , IEntity entity )
80
95
{
96
+ //IMPORTANT: we must clone to store, see: http://issues.umbraco.org/issue/U4-4259
97
+ entity = ( IEntity ) entity . DeepClone ( ) ;
98
+
81
99
_cache . AddOrUpdate ( GetCompositeId ( type , entity . Id ) , entity , ( x , y ) => entity ) ;
82
100
}
83
101
0 commit comments