Fixed Realm cache not working

I have added a unit test for this case as well. 
The error was introduced after last release, so changelog shouldn't need to be updated.  

@kneth @bmunkholm