scottohara / loot

An implementation of some of the core MS Money features in Ruby on Rails
MIT License
4 stars 3 forks source link

Deleting should remove item from LRU cache #61

Closed scottohara closed 9 years ago

scottohara commented 10 years ago

When a payee/category/security/account is deleted, if the item exists in the corresponding LRU cache it should be removed.

This will require the LruCache object returned by ogLruCacheFactory to have a remove() function, that checks if the item is in the list and if so removes it and re-links it's .newer <=> .older items together.

In the model.destroy(); attach a then() handler to the $http.delete call, eg.

model.destroy = function(payee) {
  // Flush the $http cache
  model.flush();

  return $http.delete(model.path(payee.id)).then(function() {
    model.deleteRecent(payee);
  };
};

model.deleteRecent = function(payee) {
  // Remove the item from the LRU cache (if it exists)
  model.recent = lruCache.remove(payee);

  // Update the local storage with the new list
  $window.localStorage.setItem(LRU_CACHE_STORAGE_KEY, JSON.stringify(lruCache.dump()));
};