Sobes.tech
Junior — Middle

Can you give an example of an initiative or project you implemented in your professional activity?

sobes.tech AI

Answer from AI

In one of my Node.js projects, I implemented an API response caching system to reduce database load and speed up server response times. I used Redis to store the cache with a TTL (time-to-live). When a request was made, the cache was checked first, and if the data was current, it was returned from the cache; otherwise, a database query was performed and the result was stored in the cache.

Example of using Redis in Node.js:

const redis = require('redis');
const client = redis.createClient();

async function getData(key, fetchFunction) {
  return new Promise((resolve, reject) => {
    client.get(key, async (err, data) => {
      if (err) return reject(err);
      if (data) {
        resolve(JSON.parse(data));
      } else {
        const freshData = await fetchFunction();
        client.setex(key, 3600, JSON.stringify(freshData)); // cache for 1 hour
        resolve(freshData);
      }
    });
  });
}

This significantly improved performance and reduced API response times.