title: Flutter/Dart In-memory Object Caching?
body: <p>I'm building a social media app. A user named Fred might</p>
  
  <ol>
  <li>download Fred's own profile and see it on the screen</li>
  <li>look at Fred's own followers</li>
  <li>see that Sarah is following Fred</li>
  <li>tap on Sarah's name to download Sarah's profile</li>
  <li>look at Sarah's followers</li>
  <li>see that Fred is following Sarah</li>
  <li>tap on Fred's name to see his own profile again.</li>
  </ol>
  
  <p>At this point, the stack of screens in the app is the following</p>
  
  <p>Fred &lt; Sarah &lt; Fred</p>
  
  <p>I want the <code>User</code> instance in both Fred screens to be the very same instance. Since a <code>User</code> is a <code>ChangeNotifier</code> if Fred makes a change to his own account on the top Fred profile screen, and presses the back button twice, then the bottom Fried profile screen should show the changes made.</p>
  
  <p>The stack of user screens could become arbitrarily deep as the user navigates through the app.</p>
  
  <p>My idea is that when a <code>UserScreen</code> widget asks for the <code>User</code> object, the program first checks in an in-memory cache of all <code>User</code> objects currently in use before calling the central server's JSON API.</p>
  
  <p>I want <code>User</code> objects to be garbage collected when no longer needed by any <code>Widget</code>.</p>
  
  <p>How can I keep an in-memory cache that doesn't require manually incrementing and decrementing reference counts in widget <code>initState</code> and <code>dispose</code> methods? Is there something like a weak set in Dart that I can use?</p>
  
  <p>Thanks!!!</p>