FoalTS / foal

Full-featured Node.js framework, with no complexity. 🚀 Simple and easy to use, TypeScript-based and well-documented.
https://foalts.org/
MIT License
1.88k stars 137 forks source link

Data Caching #1020

Closed mwalden2004 closed 2 years ago

mwalden2004 commented 2 years ago

Hello! I'm working on a project that requires sending many requests to third-party providers, as well as our database. To save on rate limits we cache a lot of data -- primarily JSON data. I'm suggesting a feature that would allow built-in caching through stores like Redis, and maybe even message queues.

LoicPoullain commented 2 years ago

Hi @mwalden2004 👋

Would you have an example of solution in mind? For example, something that would exist in another framework (Node, PHP, etc)?

Maybe you could call FoalTS's redis store to use sessions and cache data with them.

export class Service {
  @dependency
  store: RedisStore;

  async aFunction() {
    const session = await createSession(this.store);
    session.set(...);
    await session.commit();

    const session2 = await readSession(this.store, session.getToken());
    const data = session.get(...);
    // ...
  }

}
mwalden2004 commented 2 years ago

I am going to close this problem as I just created my own Redis service. This would likely work, but the way I did my architecture this wouldn't work. Thank you for your time though, and this library is awesome! Can't wait for WebSocket support in 2.8!