added cache system

This commit is contained in:
2026-02-12 22:22:53 +01:00
parent 991569d9eb
commit a7ef46640d
7 changed files with 120 additions and 229 deletions

View File

@@ -23,14 +23,16 @@ document.addEventListener('DOMContentLoaded', async () => {
});
async function loadOffices() {
const response = await api.get('/api/offices');
// Cache offices for dropdown (60 min)
const response = await api.getCached('/api/offices', 60);
if (response && response.ok) {
offices = await response.json();
}
}
async function loadUsers() {
const response = await api.get('/api/users');
// Cache users list (15 min)
const response = await api.getCached('/api/users', 15);
if (response && response.ok) {
users = await response.json();
renderUsers();
@@ -166,6 +168,8 @@ async function deleteUser(userId) {
const response = await api.delete(`/api/users/${userId}`);
if (response && response.ok) {
utils.showMessage('Utente eliminato', 'success');
api.invalidateCache('/api/users');
api.invalidateCache('/api/offices'); // Invalidate office counts
await loadUsers();
} else {
const error = await response.json();
@@ -210,6 +214,8 @@ function setupEventListeners() {
if (response && response.ok) {
document.getElementById('userModal').style.display = 'none';
utils.showMessage('Utente aggiornato', 'success');
api.invalidateCache('/api/users');
api.invalidateCache('/api/offices'); // Invalidate office counts
await loadUsers();
} else {
const error = await response.json();