The following changes were made by the replace_file_content tool to: /root/aadharbot/index.js. If relevant, proactively run terminal commands to execute this code for the USER. Don't ask for permission. [diff_block_start] @@ -972,36 +972,8 @@ } if (!pool) return { hasAccess: false, credits: 0, isUnlimited: false }; - - const cacheKey = `user_access:${userId}`; - - // Level 1: LRU Cache (In-Memory) - const l1Cached = userCache.get(cacheKey); - if (l1Cached) { - // Fix dates from string serialization if any - if (l1Cached.planExpiresAt && typeof l1Cached.planExpiresAt === 'string') { - l1Cached.planExpiresAt = new Date(l1Cached.planExpiresAt); - } - return applyFreeMode(l1Cached); - } - - // Level 2: Redis Cache (Persistent) - if (typeof redisClient !== 'undefined' && redisClient) { - try { - const l2Cached = await redisClient.get(cacheKey); - if (l2Cached) { - const parsed = JSON.parse(l2Cached); - if (parsed.planExpiresAt) parsed.planExpiresAt = new Date(parsed.planExpiresAt); - // Promote to L1 - userCache.set(cacheKey, parsed); - return applyFreeMode(parsed); - } - } catch (e) { - console.error("Redis L2 Cache Error:", e.message); - } - } - - // Level 3: Database (Fallback) + + // Real-time Database Check (No cache for plan/balance to avoid stale expired searches) try { const res = await pool.query('SELECT credits, plan_type, plan_expires_at FROM users WHERE telegram_id = $1', [userId]); let resultData; @@ -1019,13 +1019,6 @@ resultData = { hasAccess: false, isUnlimited: false, credits: 0, planExpiresAt: null }; } - // Save to L1 Cache - userCache.set(cacheKey, resultData); - // Save to L2 Cache (TTL 30 mins = 1800s) - if (typeof redisClient !== 'undefined' && redisClient) { - redisClient.set(cacheKey, JSON.stringify(resultData), 'EX', 1800).catch(() => {}); - } - return applyFreeMode(resultData); } catch (err) { console.error("Error in checkUserAccess:", err.message); [diff_block_end] Please note that the above snippet only shows the MODIFIED lines from the last change. It shows up to 3 lines of unchanged lines before and after the modified lines. The actual file contents may have many more lines not shown.