Skip to content

ExpressJS caching middleware #151

@TapaiBalazs

Description

@TapaiBalazs

What do you want to build?

A set of express middlewares, that can be set up with redis (or any other caching solution) and would handle API endpoint caching with just simply dropping the middlewares into the route handlers.

Where the idea come from?

While working with ExpressJS APIs, with @BigAB we had an idea: what would it look like to have a set of caching middlewares for express? Could it be done?

If we could check the cache based on the request and return the result, skipping the rest of the middlewares/routers. And conversely looking at the response after the router handlers have run an caching the result.

Would it be a good idea? Then the individual controllers do not need to know anything about the cache (or maybe they would still need to know which bits to invalidate on update if we can't generalize that behaviour).

How long will it take to build?

First we would need a POC, maybe with an in-memory storage just to see if it can be done.
We are not entirely sure if res.send() would stop executing the following middlewares/handlers, that needs to be tested.

After the POC (and if it is successful), there are some tasks that needs to be done:

  • Create an express API example in the repo that uses the middlewares
  • Design a cache-connector interface, so people can implement their own connectors with cache mechanisms other than Redis
  • Create our own redis connector
  • Document everything properly (tsdoc, readme, etc)
  • Proper testing should be done
  • Package release
  • Additional features (force re-cache, skip-cache, etc)

I'd say that depending on the POC results the first version of the package should be done rather quickly, and then we could add more and more features and configuration depths to the lib.

I'm not good with estimations, but it seems reasonable that a first version with simply allowing TTL could be done in 25-30 hours (with proper planning and architecture discussions)

Additional note:

If this package is ready, we might also be able to extend it to another package that provides the functionality to NestJS, maybe with decorators or something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions