mirror of
https://github.com/itsnaveenk/bazar3.git
synced 2025-12-19 22:57:06 +00:00
cache issue resolved
This commit is contained in:
parent
d09208c07f
commit
83721ac5d9
@ -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);
|
||||||
|
|||||||
@ -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;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user