title: AngularJS setting an object cache as dirty
body: <p>I'm using AngularJS 1.2.x for my frontend with <a href="https://vitalets.github.io/angular-xeditable/" rel="nofollow">xeditable</a> to edit items inplace and update the database. My backend is Rails 3.2.</p>
  
  <p>I have a level object which has many versions, each version has a from_date &amp; cost_cents field in which I have setup xeditable to do inline editing. The problem is after I edit these, if I refresh the screen the old values show up. If I disable caching in the browser however I get the correct values. So I need a way to flag the parent object's cache as dirty.</p>
  
  <p>Here is an example of using xeditable on a date field for a level's version. </p>
  
  <pre><code>        &lt;td editable-text="version.from_date"
              onbeforesave="update_version(level.id, version.id, $data, version.cost_cents)"
              class='date'&gt;{{version.from_date}}&lt;/td&gt;
  </code></pre>
  
  <p>Is it possible to get AngularJS or angular-xeditable to flag the parent object's cache as dirty so that it will reload the values from the database?</p>
  
  <p><strong>Update: Using a form instead</strong></p>
  
  <p>I replaced xeditable with a form and still got the same problem with caching. This doesn't happen on my development server only on staging &amp; production servers.</p>
  
  <pre><code>    &lt;form ng-submit="update_version(level.id, version.id, version.from_date, version.cost_cents)"&gt;
          Date: &lt;input type='text' id="from_date" name="version.from_date" ng-model="version.from_date" /&gt;
          Cost: &lt;input type='text' id="cost_cents" name="version.cost_cents"
                       ng-model="version.cost_cents"
                       form-cents-to-dollars /&gt;
  
          &lt;button id="update_btn" type="submit" class="confirm_btn"&gt;
              &lt;i class="fa fa-pencil"&gt;&lt;/i&gt; Update Version
          &lt;/button&gt;
          &lt;td&gt;&lt;a id="edit" href="/api#/levels/{{level.id}}/edit_version/{{version.id}}"&gt;Edit&lt;/a&gt;&lt;/td&gt;
          &lt;td&gt;&lt;a id="delete" href="" ng-confirm-click="delete_version(version.id)"&gt;
              &lt;i class="fa fa-trash-o fa-lg" /&gt;&lt;/a&gt;&lt;/td&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p><strong>Update: Deleting the cookie</strong></p>
  
  <p>If I load the staging server in firefox and do the same test, then go and delete the cookie for the current session and refresh my versions listing it now has the correct data from the database displayed. </p>
  
  <p><strong>Update: Responds 304 Not modified</strong></p>
  
  <p>The response I get is http 304: Not Modified, when infact I did modify the data, but as it's a child object AngularJS hasn't picked it up.</p>
  
  <p><strong>Update: thoughts</strong></p>
  
  <p>I'm starting to think it might be Rails which is doing the caching?</p>
  
  <p>By switching this flag to true in development I can now replicate the same problem in development mode. Which saves a lot of time.</p>
  
  <pre><code>  config.action_controller.perform_caching = true
  </code></pre>
  
  <p><strong>Update: Hacky workaround</strong></p>
  
  <p>If I tag onto the end of my AngularJS http call a random number then it doesn't call cache and it works correctly everytime. It's a bit hacky though and I would like a better way of doing this.</p>
  
  <pre><code>$http({method: 'GET', url: "/levels/#{$stateParams['id']}?rnd="+new Date().getTime(), cache: false}).
    success( (data, status, headers, config) -&gt;
      $scope.level = data
    )
  </code></pre>