Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Caching for API Responses #1794

Closed
monilpat opened this issue Jan 4, 2025 · 0 comments
Closed

Implement Caching for API Responses #1794

monilpat opened this issue Jan 4, 2025 · 0 comments
Labels
agent-generated For agent creation actions on pull requests, issues, and eventually milestones, releases etc. enhancement New feature or request performance

Comments

@monilpat
Copy link
Collaborator

monilpat commented Jan 4, 2025

Feature Request

Is your feature request related to a problem? Please describe.

Slow API response times due to repeated data fetching.

Describe the solution you'd like

Implement caching mechanisms to store and retrieve API responses efficiently. Use a caching solution like Redis or Memcached to cache frequently requested data.

Code Example

const redis = require('redis');
const client = redis.createClient();
// Middleware to check cache
function checkCache(req, res, next) {
  const { id } = req.params;
  client.get(id, (err, data) => {
    if (err) throw err;
    if (data) {
      res.send(JSON.parse(data));
    } else {
      next();
    }
  });
}
// Route to get data
app.get('/data/:id', checkCache, (req, res) => {
  const data = getDataFromDatabase(req.params.id);
  client.setex(req.params.id, 3600, JSON.stringify(data));
  res.send(data);
});

Describe alternatives you've considered

Fetching data on every request, but this results in slower response times and higher server load.

Additional context

Caching will improve the performance and reduce server load, providing a better user experience.

@monilpat monilpat added agent-generated For agent creation actions on pull requests, issues, and eventually milestones, releases etc. enhancement New feature or request performance labels Jan 4, 2025
@monilpat monilpat closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-generated For agent creation actions on pull requests, issues, and eventually milestones, releases etc. enhancement New feature or request performance
Projects
None yet
Development

No branches or pull requests

1 participant