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

maxAge: 0 should disable the cache #78

Open
Junkern opened this issue May 9, 2017 · 4 comments
Open

maxAge: 0 should disable the cache #78

Junkern opened this issue May 9, 2017 · 4 comments
Assignees
Milestone

Comments

@Junkern
Copy link

Junkern commented May 9, 2017

When using memoizee, I inject a config variable as the value for maxAge so I can use different values for different environments (prod, dev, testing...).

When setting maxAge: 0 I would expect that the cache is disabled, as every value is cached for 0 milliseconds.. This seems not to be the case, however.

More information, if needed:
On production I use memoizee to minimize calls to other services, to reduce the load.
For testing, I am using nock to mock HTTP responses. At the end of ever test I am verifying if all mocked calls finished successfully. I want that every mocked HTTP response is called, so I want to disable the cache,.

I could introduce a environment flag and then decide based on that whether I memoizee a function or not. But I think maxAge: 0 would be more elegant.

@medikoo medikoo self-assigned this May 9, 2017
@medikoo
Copy link
Owner

medikoo commented May 9, 2017

Thanks for reporting, interesting use case. Currently this setting follows setTimeout behavior. So 0 delays cache purge until callback in setTimeout(fn, 0) is released.

Still I agree that it might be nicer, if it just disables the cache in such case

@medikoo medikoo added this to the v1 milestone May 9, 2017
@Junkern
Copy link
Author

Junkern commented May 9, 2017

Thanks for the quick response!

I still have one question:

So 0 delays cache purge until callback in setTimeout(fn, 0) is released

Do you mean, that the cache is purged after the callback is finished? (So after the memoizeed function has finished its first call?)

@medikoo
Copy link
Owner

medikoo commented May 9, 2017

Do you mean, that the cache is purged after the callback is finished? (So after the memoizeed function has finished its first call?)

Sorry, no, in case of 0 whole maxAge setting is ignored. However if you pass 1 you'll have cached purged shortly after call.

@Junkern
Copy link
Author

Junkern commented May 9, 2017

Makes totally sense. I also have looked into the code and seen the if (!maxAge) return; but I thought maybe the line before (maxAge = timeout(maxAge);) introduces some magic.

I am passing 1 for now, but I would be happy if 0will disable the cache:)

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

No branches or pull requests

2 participants