@@ -837,6 +837,15 @@ class LRUCache {
837
837
if ( v !== oldVal ) {
838
838
if ( this . #hasFetchMethod && this . #isBackgroundFetch( oldVal ) ) {
839
839
oldVal . __abortController . abort ( new Error ( 'replaced' ) ) ;
840
+ const { __staleWhileFetching : s } = oldVal ;
841
+ if ( s !== undefined && ! noDisposeOnSet ) {
842
+ if ( this . #hasDispose) {
843
+ this . #dispose?. ( s , k , 'set' ) ;
844
+ }
845
+ if ( this . #hasDisposeAfter) {
846
+ this . #disposed?. push ( [ s , k , 'set' ] ) ;
847
+ }
848
+ }
840
849
}
841
850
else if ( ! noDisposeOnSet ) {
842
851
if ( this . #hasDispose) {
@@ -1090,15 +1099,15 @@ class LRUCache {
1090
1099
const pcall = ( res , rej ) => {
1091
1100
const fmp = this . #fetchMethod?. ( k , v , fetchOpts ) ;
1092
1101
if ( fmp && fmp instanceof Promise ) {
1093
- fmp . then ( v => res ( v ) , rej ) ;
1102
+ fmp . then ( v => res ( v === undefined ? undefined : v ) , rej ) ;
1094
1103
}
1095
1104
// ignored, we go until we finish, regardless.
1096
1105
// defer check until we are actually aborting,
1097
1106
// so fetchMethod can override.
1098
1107
ac . signal . addEventListener ( 'abort' , ( ) => {
1099
1108
if ( ! options . ignoreFetchAbort ||
1100
1109
options . allowStaleOnFetchAbort ) {
1101
- res ( ) ;
1110
+ res ( undefined ) ;
1102
1111
// when it eventually resolves, update the cache.
1103
1112
if ( options . allowStaleOnFetchAbort ) {
1104
1113
res = v => cb ( v , true ) ;
0 commit comments