title: Android: SQLite, UI, caching and async queries
body: <p>I have a custom view that loads a model object (let's call it <code>Person</code>, why not). These objects are stored in a DB, obtained through a <code>Loader</code> and inserted into a <code>ListView</code> through a <code>CursorAdapter</code> that instantiates said views. So far, so good.</p>
  
  <p>Now, <code>Person</code> has a reference to another model object, let's say <code>Country</code>. <code>Countries</code> are in its own table, and I need the name of the country (having the ID, of course) to represent it in the list items.</p>
  
  <p>I see three options:</p>
  
  <ol>
  <li><p>Query the database from the view method that loads the Person data (<code>setPerson()</code>?).</p></li>
  <li><p>Deep pre-load (I think I just made a term up, sorry) my model objects with the Country information.</p></li>
  <li><p>Request that the Country data be asynchronously queried and then brought back to the UI.</p></li>
  </ol>
  
  <p>The problem with (1) is that the UI may block. The problem with (2) is that it leads to heavy data duplication in memory. The problem with (3) is that it complicates flow, maybe unnecessarily.</p>
  
  <p>What should I do? Is the performance hit of (1) important? Maybe (1), query the data from the View, but implement a cache to avoid hitting the database repeatedly for the same <code>Country</code>? Maybe (2), with said cache layer to ensure instances of the object are unique? A 4th option I haven't considered? What do ORMs do?</p>
  
  <p>Thanks!</p>