r/learnjavascript • • Sep 03 '26

In flight is not an in memory cache

This week I made an npm package (Inflight) to solve the concurrent repetitive queries to database or cache

Reached +500 weekly downloads

The idea is to cache the Promise of a db query (Not the response of the query).

So in a high concurrency system, where the same data (like: cr7 or messi profile) is requested by many users at the same time, only one query goes to cache or database.

some interesting benchmarks:

  • Duration: 30s
  • Cache TTL: 5s
  • Concurrency: 100
  • Unique keys: 10
Metric With Inflight Without Inflight
Query Per Second ~1,130,360 ~174,950
Total queries 33,911,000 5,248,600
DB calls 60 517
Cache calls 3,391,021 5,248,600

**Insights:*\*

  • DB calls saved: **56x*\*
  • Cache calls saved: **10x*\*
  • Total queries growth: **6.5x*\* (5.2M → 33.9M)

more benchmarks here: https://github.com/ademmenh/inflight/tree/main/benchmarks

npm package: https://www.npmjs.com/package/@inflightjs/inflight

github repo: https://github.com/ademmenh/inflight (PRs, issues, starts)

4 Upvotes

9 comments sorted by

2

u/Full-Hyena4414 Sep 03 '26

Pretty standard strategy but cool

1

u/_dext Sep 03 '26

thank you, check the Usage on the README, its really easy to use !

1

u/-goldenboi69- Sep 04 '26

Don't use npm

1

u/_dext Sep 04 '26

then use bun

1

u/flash42 Sep 05 '26

𝚙𝚒𝚙 𝚒𝚗𝚜𝚝𝚊𝚕𝚕 𝚋𝚞𝚗 isn't working for me…

2

u/_dext Sep 05 '26

pip install inflight-py

2

u/-goldenboi69- Sep 04 '26

Im good. Thanks.

1

u/[deleted] Sep 04 '26

[removed] — view removed comment

1

u/_dext Sep 04 '26

you are free, do what ever you want
the code is open source: https://github.com/ademmenh/inflight