Closed subvertnormality closed 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.
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.
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.
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.
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.
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?