goodeggs / angular-cached-resource

An AngularJS module to interact with RESTful resources, even when browser is offline
MIT License
216 stars 29 forks source link

Programmatically adding items to the cache #19

Closed hazeledmands closed 10 years ago

hazeledmands commented 10 years ago

Pretty much the opposite of #8. It would be really useful (esp. in unit tests) to add items to the cache programmatically.

Perhaps something like:

var Resource = $cachedResource('derp', '/derp/:id', { id: '@id' });

// class method
Resource.$addToCache({herp: true, id: 1234}); // returns resource instance

// instance method
var item = new Resource({herp: true, id: 1234});
item.$$addToCache()

Using $$ instead of $ to namespace this as a "special" action that doesn't involve HTTP and can't be overridden.

hazeledmands commented 10 years ago

This would be particularly useful for cleaning up the tests, too.