How to completely destroy and recreate a Realm database
<p>I have an application using Realm.io that on logout, we totally destroy the realm cache that has been built up by the user so that when a new user logs in, we can recreate the cache file for the next user. </p>

<p>Deleting all objects is not an option as the realm file is encrypted using a hash of the users passcode so it has to be a fresh Realm (AFAIK).</p>

<p>Currently I am deleting the Realm file like so:</p>

<pre><code>NSString *realmFile = [[DCMCacheManager documentsDirectoryPath] stringByAppendingPathComponent:@"myApp.realm"];
NSFileManager *localFileManager = [NSFileManager new];

[localFileManager removeItemAtPath:realmFile error:&amp;error];
</code></pre>

<p>And reinstating it using:</p>

<pre><code>RLMRealm * realm = [RLMRealm realmWithConfiguration:config error:&amp;error];
</code></pre>

<p>When the creation code runs for the first time the realm file is created with no issues. When I try to recreate it after deleting, the app seems to return an internally cached version of the realm file so does not create the myApp.realm file for me.</p>

<p>Any suggestions on how to make sure the realm is absolutely dead when I delete it?</p>