restangular-object-cache
R.O.C. The Restangular Object Cache
What is this?
The Restangular Object Cache is a cache and relationship wiring system for Restangular. You may use it to attach two Restangular objects together by hasMany or belongsTo relationships. You may also use it as a centralized object store for all of the objects you have received from the server during the lifetime of your application.
Usage
angularmodule'my-app''restangular''restangular-object-cache' angularmodule'my-app'factory 'EmployeesService' RestangularObjectCachetrack 'employees' # tell the object cache to watch the model 'employees' RestangularObjectCacheindex 'employees''account_id' # allow fast lookups by account_id RestangularObjectCachedefineRelationships 'employees' relationshipsbelongsTo 'accounts' # add a method called account() return Restangularservice'employees' angularmodule'my-app'factory 'AccountsService' RestangularObjectCachetrack 'accounts' RestangularObjectCachedefineRelationships 'accounts' relationshipshasMany 'employees' # add a method called employees() return Restangularservice'accounts' angularmodule'my-app'controller 'AccountsController' EmployeesServicegetListthen -> AccountsServicegetListthen $scope.accounts = accounts = accountemployees
Tracking
Use 'track' to add named tracking of a particular model in the cache. By default they will be tracked by 'id'.
Relationships
You may use 'hasMany' and 'belongsTo' to wire relationships between models.