title: Repository pattern with changing data on server over time
body: <p>I am following <strong>Clean Architecture</strong> proposed by famous <strong>Robert C. Martin</strong>. The birds eye view of Clean Architecture looks like as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/RBitn.png" rel="noreferrer"><img src="https://i.stack.imgur.com/RBitn.png" alt="enter image description here"></a>
  However right now my concern about <strong>Repository pattern modification</strong>. Basics steps of Repository pattern are:</p>
  
  <blockquote>
    <ol>
    <li>Search in-memory cache AND provide data to app layer</li>
    <li>If not found, search local data source AND sync to in-memory cache AND provide data to app layer</li>
    <li>If not found, search remote data source AND sync to local data source AND provide data to app layer</li>
    </ol>
  </blockquote>
  
  <p><strong>Following above steps strictly, if a data exists in local data source it will never sync from remote data source while data might be changed in remote. How can I modify so that this case could be handled ? One idea comes in my mind written below, but I am looking to a better solution indeed.</strong></p>
  
  <p>My idea is to keep track of last sync time for each record in local database. If last sync time is more than a threshold time ago, then sync automatically.</p>