hapijs / catbox-memory

Memory adapter for catbox
Other
33 stars 30 forks source link

Implementation that does not require setTimeout #49

Closed subvertnormality closed 7 years ago

subvertnormality commented 7 years ago

This is more of a proof of concept than anything else, I'd like your input as to why this approach is not desirable and/or feasible.

We're interested in an approach that does not require setTimeout as we suspect this may cause problems in an AWS Lambda environment due to the way the event loop is managed there. Are there any obvious issues with this approach that I am missing?

kanongil commented 7 years ago

You could implement https://github.com/hapijs/catbox-memory/issues/8#issuecomment-242635093, and set the interval to Infinity or something for your use-case.

subvertnormality commented 7 years ago

I'm interested in the reason why we need setIntervals at all? Surely the cache can just be cleared at the next get request since there's no issues with latency when removing an item from a memory store. Am I missing something obvious? It seems this PR would solve https://github.com/hapijs/catbox-memory/issues/8 by not using timeouts at all - expired cache items would simply be cleared on fetch.

subvertnormality commented 7 years ago

Ah, I've just seen the comment from @hueniverse on #36 about cache items not being cleared out from memory unless they are fetched. It's a fair point.

subvertnormality commented 7 years ago

I see this doesn't make sense in the wider context of the library.

However, I feel it has some merit in applications using AWS lambdas where things are a bit different. Although memory caches in lambdas are discouraged, we have a production need to have some form of memory caching for if/when our Redis instances fail.

I plan to work on a fork - when the cache size reaches the maxByteSize it will run a function to tidy up any expired cache values that exist in memory (thus flushing any items that have not been fetched recently). This is actually unlikely to happen in a serverless world since the lambdas (and memory along with it) are thrown away regularly anyway. I think this would actually solve #36 and #8 in a round about way when running on traditional servers, but it wouldn't be efficient since the memory cache would eventually be running up to the maxByteSize and then dipping back down on a flush.

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.