How To Setup Caching in Nodejs

How To Setup Caching in Nodejs

How to use decorators to implement in a few lines of code a coaching mechanism for both node and web application

In this article I would like to show you how you could use the @memoizeAsync decorator, from the utils-decorators library, in your application (both node and web) in one of the most elegant and simple ways.

Let’s say we have the following class:

export class SettingsProviderClient {
  getSettings(context): Promise<SettingsDto> {

As you can see, the getSettings is returning a Promise of SeettingsDto. Now let’s say that we would like to have some caching which will check if a call was made in the last 10 minutes to getSettings with the same context then it would be pulled from the cache and won’t be resolved again.

First step, install the utils-decorators library:

npm install --save utils-decorators

typescript javascript nodejs

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

The What, Why, and How of TypeScript for JavaScript Developers

A typed introduction to JavaScript .The What, Why, and How of TypeScript for JavaScript Developers

What is TypeScript? Why TypeScript? and Why Not TypeScript?

TypeScript extends JavaScript by adding Types. There are many great reasons to switch to TypeScript. Especially if your team uses JavaScript. There are some reasons to not use TypeScript as there are with any language or framework.

Decoding Nodejs

The main goal of this blog is to explain the “Architecture of Nodejs” and to know how the Nodejs works behind the scenes. Generally, most of the server-side languages, like PHP, ASP.NET, Ruby, and including Nodejs follows multi-threaded architecture. That means for each client-side request initiates a new thread or even a new process.

Hire NodeJs Developer

Looking to build dynamic, extensively featured, and full-fledged web applications? **[Hire NodeJs Developer]( "Hire NodeJs Developer")** to create a real-time, faster, and scalable...

Migrating from JavaScript to TypeScript (from scratch)

In this tutorial, we will talk about how to Switch from JavaScript to TypeScript . Scripts typically require some level of tinkering and tweaking to get the desired output. If written in JavaScript, developers have to remember the shape of input and output. I personally have to log output to recall what I’m getting as a response.