@@ -1858,6 +1858,8 @@ var errorPrefix = 'DS.find(resourceName, id[, options]): ';
1858
1858
* @param {string|number } id The primary key of the item to retrieve.
1859
1859
* @param {object= } options Optional configuration. Properties:
1860
1860
* - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
1861
+ * - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
1862
+ *
1861
1863
* @returns {Promise } Promise produced by the `$q` service.
1862
1864
*
1863
1865
* ## Resolves with:
@@ -1883,6 +1885,11 @@ function find(resourceName, id, options) {
1883
1885
} else if ( ! this . utils . isObject ( options ) ) {
1884
1886
deferred . reject ( new this . errors . IllegalArgumentError ( errorPrefix + 'options: Must be an object!' , { options : { actual : typeof options , expected : 'object' } } ) ) ;
1885
1887
} else {
1888
+ if ( ! ( 'cacheResponse' in options ) ) {
1889
+ options . cacheResponse = true ;
1890
+ } else {
1891
+ options . cacheResponse = ! ! options . cacheResponse ;
1892
+ }
1886
1893
try {
1887
1894
var definition = this . definitions [ resourceName ] ,
1888
1895
resource = this . store [ resourceName ] ,
@@ -1896,10 +1903,14 @@ function find(resourceName, id, options) {
1896
1903
if ( ! ( id in resource . pendingQueries ) ) {
1897
1904
promise = resource . pendingQueries [ id ] = _this . adapters [ options . adapter || definition . defaultAdapter ] . find ( definition , id , options )
1898
1905
. 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
+ }
1903
1914
} ) ;
1904
1915
}
1905
1916
@@ -1960,10 +1971,14 @@ function _findAll(utils, resourceName, params, options) {
1960
1971
// This particular query has never even been made
1961
1972
resource . pendingQueries [ queryHash ] = _this . adapters [ options . adapter || definition . defaultAdapter ] . findAll ( definition , { params : params } , options )
1962
1973
. 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 ;
1967
1982
}
1968
1983
} ) ;
1969
1984
}
@@ -2026,6 +2041,7 @@ function _findAll(utils, resourceName, params, options) {
2026
2041
*
2027
2042
* @param {object= } options Optional configuration. Properties:
2028
2043
* - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
2044
+ * - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
2029
2045
*
2030
2046
* @returns {Promise } Promise produced by the `$q` service.
2031
2047
*
@@ -2053,6 +2069,11 @@ function findAll(resourceName, params, options) {
2053
2069
} else if ( ! this . utils . isObject ( options ) ) {
2054
2070
deferred . reject ( new this . errors . IllegalArgumentError ( errorPrefix + 'options: Must be an object!' , { options : { actual : typeof options , expected : 'object' } } ) ) ;
2055
2071
} else {
2072
+ if ( ! ( 'cacheResponse' in options ) ) {
2073
+ options . cacheResponse = true ;
2074
+ } else {
2075
+ options . cacheResponse = ! ! options . cacheResponse ;
2076
+ }
2056
2077
try {
2057
2078
promise = promise . then ( function ( ) {
2058
2079
return _findAll . apply ( _this , [ _this . utils , resourceName , params , options ] ) ;
@@ -2779,6 +2800,7 @@ function eject(resourceName, id) {
2779
2800
_eject ( _this . definitions [ resourceName ] , resource , id ) ;
2780
2801
resource . collectionModified = _this . utils . updateTimestamp ( resource . collectionModified ) ;
2781
2802
}
2803
+ delete this . store [ resourceName ] . completedQueries [ id ] ;
2782
2804
} catch ( err ) {
2783
2805
throw new this . errors . UnhandledError ( err ) ;
2784
2806
}
0 commit comments