Website : rimsha.abasa.com
backdoor
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
mudeerapi.abasa.com
/
nodetest
/
src
/
utils
/
Filename :
invalidationHelper.js
back
Copy
import { cacheHelper } from './cacheHelper.js'; /** * Cache Invalidation Helper * Centralized invalidation logic for different resource types */ export const invalidateCache = { /** * Invalidate attendance-related caches * Called after: markAttendance, updateAttendance, massUpdateHoliday, attendanceCheckout * @param {string} userId - User ID whose attendance changed */ attendance: async (userId) => { try { console.log(`Invalidating attendance cache for user: ${userId}`); // Delete all attendance queries for this user await cacheHelper.deletePattern(`attendance:${userId}:*`); // Note: In future, also invalidate: // - users:list:* (affects user list with attendance status) // - user:detail:{userId} (affects user detail with attendance) // - leave:info:{userId} (affects leave balance if leave type) console.log(`✓ Attendance cache invalidated for user: ${userId}`); } catch (error) { console.error('Attendance cache invalidation error:', error.message); } }, /** * Invalidate attendance for multiple users (batch operations) * Called after: massUpdateHoliday (when updating entire company) * @param {string[]} userIds - Array of user IDs */ attendanceBatch: async (userIds) => { try { console.log(`Invalidating attendance cache for ${userIds.length} users`); for (const userId of userIds) { await cacheHelper.deletePattern(`attendance:${userId}:*`); } console.log(`✓ Attendance cache invalidated for ${userIds.length} users`); } catch (error) { console.error('Batch attendance cache invalidation error:', error.message); } }, /** * Invalidate all attendance caches (nuclear option) * Use sparingly - for company-wide updates only */ attendanceAll: async () => { try { console.log('Invalidating ALL attendance caches'); await cacheHelper.deletePattern('attendance:*'); console.log('✓ All attendance caches invalidated'); } catch (error) { console.error('All attendance cache invalidation error:', error.message); } }, // Placeholder for future implementations /** * Invalidate user-related caches * Called after: updateUser, deactivateUser, deleteUserData (when isActive changes) * @param {string} userId - User ID */ user: async (userId) => { try { console.log(`Invalidating user cache for: ${userId}`); // Invalidate user list caches (isActive changes affect user lists) await cacheHelper.deletePattern(`users:list:*`); // Invalidate specific user detail cache await cacheHelper.delete(`user:detail:${userId}`); // Invalidate attendance cache (user status affects attendance display) await cacheHelper.deletePattern(`attendance:${userId}:*`); console.log(`✓ User cache invalidated for: ${userId}`); } catch (error) { console.error('User cache invalidation error:', error.message); } }, /** * Invalidate department-related caches * @param {string} departmentId - Department ID */ department: async (departmentId = null) => { // TODO: Implement when department caching is added console.log(`TODO: Invalidate department cache for: ${departmentId || 'all'}`); }, /** * Invalidate notification-related caches * @param {string} userId - User ID */ notification: async (userId) => { // TODO: Implement when notification caching is added console.log(`TODO: Invalidate notification cache for: ${userId}`); }, /** * Invalidate leave-related caches * @param {string} userId - User ID */ leave: async (userId) => { // TODO: Implement when leave caching is added console.log(`TODO: Invalidate leave cache for: ${userId}`); } };