@@ -1858,6 +1858,8 @@ var errorPrefix = 'DS.find(resourceName, id[, options]): ';
18581858 * @param {string|number } id The primary key of the item to retrieve.
18591859 * @param {object= } options Optional configuration. Properties:
18601860 * - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
1861+ * - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
1862+ *
18611863 * @returns {Promise } Promise produced by the `$q` service.
18621864 *
18631865 * ## Resolves with:
@@ -1883,6 +1885,11 @@ function find(resourceName, id, options) {
18831885 } else if ( ! this . utils . isObject ( options ) ) {
18841886 deferred . reject ( new this . errors . IllegalArgumentError ( errorPrefix + 'options: Must be an object!' , { options : { actual : typeof options , expected : 'object' } } ) ) ;
18851887 } else {
1888+ if ( ! ( 'cacheResponse' in options ) ) {
1889+ options . cacheResponse = true ;
1890+ } else {
1891+ options . cacheResponse = ! ! options . cacheResponse ;
1892+ }
18861893 try {
18871894 var definition = this . definitions [ resourceName ] ,
18881895 resource = this . store [ resourceName ] ,
@@ -1896,10 +1903,14 @@ function find(resourceName, id, options) {
18961903 if ( ! ( id in resource . pendingQueries ) ) {
18971904 promise = resource . pendingQueries [ id ] = _this . adapters [ options . adapter || definition . defaultAdapter ] . find ( definition , id , options )
18981905 . then ( function ( data ) {
1899- // Query is no longer pending
1900- delete resource . pendingQueries [ id ] ;
1901- resource . completedQueries [ id ] = new Date ( ) . getTime ( ) ;
1902- return _this . inject ( resourceName , data ) ;
1906+ if ( options . cacheResponse ) {
1907+ // Query is no longer pending
1908+ delete resource . pendingQueries [ id ] ;
1909+ resource . completedQueries [ id ] = new Date ( ) . getTime ( ) ;
1910+ return _this . inject ( resourceName , data ) ;
1911+ } else {
1912+ return data ;
1913+ }
19031914 } ) ;
19041915 }
19051916
@@ -1960,10 +1971,14 @@ function _findAll(utils, resourceName, params, options) {
19601971 // This particular query has never even been made
19611972 resource . pendingQueries [ queryHash ] = _this . adapters [ options . adapter || definition . defaultAdapter ] . findAll ( definition , { params : params } , options )
19621973 . then ( function ( data ) {
1963- try {
1964- return processResults . apply ( _this , [ utils , data , resourceName , queryHash ] ) ;
1965- } catch ( err ) {
1966- throw new _this . errors . UnhandledError ( err ) ;
1974+ if ( options . cacheResponse ) {
1975+ try {
1976+ return processResults . apply ( _this , [ utils , data , resourceName , queryHash ] ) ;
1977+ } catch ( err ) {
1978+ throw new _this . errors . UnhandledError ( err ) ;
1979+ }
1980+ } else {
1981+ return data ;
19671982 }
19681983 } ) ;
19691984 }
@@ -2026,6 +2041,7 @@ function _findAll(utils, resourceName, params, options) {
20262041 *
20272042 * @param {object= } options Optional configuration. Properties:
20282043 * - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
2044+ * - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
20292045 *
20302046 * @returns {Promise } Promise produced by the `$q` service.
20312047 *
@@ -2053,6 +2069,11 @@ function findAll(resourceName, params, options) {
20532069 } else if ( ! this . utils . isObject ( options ) ) {
20542070 deferred . reject ( new this . errors . IllegalArgumentError ( errorPrefix + 'options: Must be an object!' , { options : { actual : typeof options , expected : 'object' } } ) ) ;
20552071 } else {
2072+ if ( ! ( 'cacheResponse' in options ) ) {
2073+ options . cacheResponse = true ;
2074+ } else {
2075+ options . cacheResponse = ! ! options . cacheResponse ;
2076+ }
20562077 try {
20572078 promise = promise . then ( function ( ) {
20582079 return _findAll . apply ( _this , [ _this . utils , resourceName , params , options ] ) ;
@@ -2779,6 +2800,7 @@ function eject(resourceName, id) {
27792800 _eject ( _this . definitions [ resourceName ] , resource , id ) ;
27802801 resource . collectionModified = _this . utils . updateTimestamp ( resource . collectionModified ) ;
27812802 }
2803+ delete this . store [ resourceName ] . completedQueries [ id ] ;
27822804 } catch ( err ) {
27832805 throw new this . errors . UnhandledError ( err ) ;
27842806 }
0 commit comments