cache issue resolved

This commit is contained in:
Naveen Kumar 2025-03-20 01:39:48 +05:30
parent d09208c07f
commit 83721ac5d9
2 changed files with 11 additions and 0 deletions

View File

@ -10,6 +10,13 @@ const teamRoutes = require('./routes/team');
const app = express(); const app = express();
// Clear cache for all admin routes
app.use('/admin', (req, res, next) => {
console.log('Clearing cache for admin API hit...');
cache.store.clear();
next();
});
app.use(cors({ origin: ['http://localhost:3000', '*', 'https://your-production-domain.com'] })); app.use(cors({ origin: ['http://localhost:3000', '*', 'https://your-production-domain.com'] }));
app.use(express.json({ limit: '10kb' })); app.use(express.json({ limit: '10kb' }));
app.use(security.anonymizeIP); app.use(security.anonymizeIP);

View File

@ -39,10 +39,13 @@ exports.getTodayResults = async () => {
const today = new Date().toISOString().split('T')[0]; const today = new Date().toISOString().split('T')[0];
const cacheKey = `today:${today}`; const cacheKey = `today:${today}`;
console.log(`Cache key: ${cacheKey}`);
if (cache.has(cacheKey)) { if (cache.has(cacheKey)) {
console.log('Cache hit for today\'s results.');
return cache.get(cacheKey); return cache.get(cacheKey);
} }
console.log('Cache miss. Fetching results from the database...');
const results = await db.query(` const results = await db.query(`
SELECT t.name AS team, r.result_time, SELECT t.name AS team, r.result_time,
CASE CASE
@ -54,6 +57,7 @@ exports.getTodayResults = async () => {
WHERE DATE(r.result_time) = ? WHERE DATE(r.result_time) = ?
`, [today]); `, [today]);
console.log('Caching today\'s results...');
cache.set(cacheKey, results); cache.set(cacheKey, results);
return results; return results;
}; };