Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ISR: Avoiding immense cache-keys generation (Adding the possibility of defining a custom cacheKey) #1743

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

Closed
sihu opened this issue Jul 3, 2024 · 2 comments Β· Fixed by #1757
Closed
Assignees

Comments

@sihu
Copy link

sihu commented Jul 3, 2024

Problem Solved By The Feature

This is related to #1720 but would be a bit more generic
This is related to #1604 but the fix done there is not fixing the issue described here

We experienced problems using the ISR library since attackers tried to access a lot of urls. Since getCacheKey uses the req.url this will lead to a separate cache-entry for each request. Within short time it filled our cache with more than 15GB of data. We had to patch the library in order to use req.path for now.

E.g.

  • Changing parameters: /my-route?1, /my-route?something=1, , /my-route?something=3 ...
  • Calling 404 pages: /something-404 that would look exactly the same but are not

I'm aware that this might be the wanted behaviour because of pagination etc. But i want to have the control of modifying this and i am not sure if it's the best default. For simple pages req.path could be an alternative. Even with pagination one could simply iterate over pages and generate an immense amount of entries.

For the 404-Pages I found the solution to not cache it (revalidate: null). I will gladly add this as a hint to the documentation to protect other users. So i cannot cache the 404 page, but i also don't create a new entry for every 404-page called.

Solution

I would suggest a configuration that lets you specifying your cacheKey-Function. Ideally the interface would allow to pass in the req and then users could still allow certain params.

For the 404-problem i was first thinking of having a beforeAddingToCache-hook where i can decide from the given response-code if i want to cache it or not.

Alternatives Considered

I did not come up with any other ideas, but happy to discuss it here!

My current workaround:

@eneajaho eneajaho self-assigned this Jul 18, 2024
maxisam added a commit to maxisam/rx-angular that referenced this issue Aug 22, 2024
@maxisam
Copy link
Contributor

maxisam commented Aug 22, 2024

@eneajaho I just push a commit to my own fork to handle this, since my company has the same issue. (We used to use our own library to handle SSR, similar with your ISR actually)

The idea of the commited change is basically like

  1. create an array for allowed query params, so when url comes in, it will only preserve the allowed query params and store as cache key.
  2. if it is null or undefined, the behavior remain the same
  3. if it is empty array, the behavior is like using req.path

I add a bit of unit test for it to ensure the behavior works as it should be.

Let me know what you think, I am fine with different approach.

maxisam added a commit to maxisam/rx-angular that referenced this issue Aug 23, 2024
eneajaho pushed a commit to maxisam/rx-angular that referenced this issue Aug 31, 2024
eneajaho pushed a commit to maxisam/rx-angular that referenced this issue Aug 31, 2024
eneajaho pushed a commit that referenced this issue Aug 31, 2024
* feat(isr): add allowed query params options #1743
* docs(isr): add doc for allowed query params option
@eneajaho
Copy link
Member

Hi @sihu
I guess the fix in #1757 should get the job done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants