node-lru-cache
node-lru-cache copied to clipboard
Is the signal passed to the fetchMethod always triggering the abort event?
Hello! 👋
I did some testing related to implementing this cache in our project, and it seemed that the abort
event was always triggered, even though everything else worked as expected. The data was fetched and cached, no problems. But when I added an event handler, it always logged. Something like this (this an excerpt of the code):
this.cache = new LRUCache<string, T, Context<T>>({
max: 300,
ttl,
fetchMethod: async (key: string, staleValue: T | undefined, { signal, context }): Promise<T | undefined> => {
signal.addEventListener('abort', () => {
console.log('ABORTED');
});
signal.onabort = (e) => {
console.log('aborted?', e);
};
// Fetches and returns data
}
});
Could it be related to allowStale
being true
?
If this is not expected behaviour, then I'll see if I can get a repro up.
The fetch will be aborted if it has not yet resolved, and the data is deleted or overwritten in the cache.
If it's firing all the time, even when that's not the case, then yes, I'd call that a bug. Repro test much appreciated!
Can't figure out what the issue is from the info provided here, and seems to work for me. Will re-open if reproduction case is provided.