Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the signal passed to the fetchMethod always triggering the abort event? #319

Closed
petertflem opened this issue Sep 20, 2023 · 2 comments
Closed

Comments

@petertflem
Copy link

petertflem commented Sep 20, 2023

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.

@isaacs
Copy link
Owner

isaacs commented Sep 20, 2023

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!

@isaacs
Copy link
Owner

isaacs commented Jun 27, 2024

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.

@isaacs isaacs closed this as completed Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants