Clear all cached data from your Odoo PWA application.
Clears all cached data from Odoo PWA including localStorage, IndexedDB, and browser cache
/plugin marketplace add jamshu/jamshi-marketplace/plugin install odoo-pwa-generator@jamshi-marketplaceClear all cached data from your Odoo PWA application.
// Clear localStorage
localStorage.clear();
// Clear and refresh
localStorage.clear();
location.reload();
// Using cache store method
expenseCache.clearCache();
expenseCache.refresh();
Add a button to your app:
<button onclick={() => {
if (confirm('Clear all cached data?')) {
expenseCache.clearCache();
expenseCache.refresh();
}
}}>
Clear Cache
</button>
□ Save any unsaved work
□ Ensure internet connection
□ Note current state (for comparison)
□ Close other tabs with same app
// Clear all
localStorage.clear();
// Or clear specific keys
localStorage.removeItem('expenseCache');
localStorage.removeItem('taskCache');
localStorage.removeItem('partnerCache');
// Via DevTools:
// 1. Open DevTools (F12)
// 2. Go to Application tab
// 3. Expand IndexedDB in left sidebar
// 4. Right-click on database → Delete
// Or programmatically:
indexedDB.deleteDatabase('odoo-pwa-db');
// Unregister service worker
navigator.serviceWorker.getRegistrations()
.then(registrations => {
registrations.forEach(reg => reg.unregister());
});
// Clear all caches
caches.keys()
.then(keys => Promise.all(
keys.map(key => caches.delete(key))
));
Chrome/Edge: Ctrl+Shift+Delete → Select cache → Clear
Firefox: Ctrl+Shift+Delete → Select cache → Clear now
Safari: Cmd+Option+E
Windows/Linux: Ctrl+Shift+R or Ctrl+F5
Mac: Cmd+Shift+R
// Check localStorage is empty
console.log('localStorage size:', localStorage.length);
// Check IndexedDB
// DevTools → Application → IndexedDB
// Should be empty or recreated
// Check cache stores
console.log('Records:', $expenseCache.length);
// Should be 0 or freshly fetched
// Clear just expense cache
localStorage.removeItem('expenseCache');
// Refresh that cache
expenseCache.refresh();
// Get current cache data
const cacheData = JSON.parse(localStorage.getItem('expenseCache'));
// Reset only metadata
cacheData.lastSyncTime = 0;
cacheData.lastRecordId = 0;
// Save back
localStorage.setItem('expenseCache', JSON.stringify(cacheData));
// Force sync
expenseCache.refresh();
// Keep only recent records (last 30 days)
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
expenseCache.records.update(records =>
records.filter(r => new Date(r.x_studio_date) > thirtyDaysAgo)
);
// Clear and reset store
import { expenseCache } from '$lib/stores/expenseCache';
expenseCache.clearCache();
expenseCache.load(); // Reload fresh data
// Using Context
import { useExpense } from './contexts/ExpenseContext';
function ClearCacheButton() {
const { clearCache, refresh } = useExpense();
return (
<button onClick={() => {
clearCache();
refresh();
}}>
Clear Cache
</button>
);
}
// Using Pinia store
import { useExpenseStore } from '@/stores/expenseStore';
const expenseStore = useExpenseStore();
function clearAndRefresh() {
expenseStore.clearCache();
expenseStore.load();
}
// Clear cache older than 7 days
const CACHE_MAX_AGE = 7 * 24 * 60 * 60 * 1000; // 7 days
function checkCacheAge() {
const cacheData = JSON.parse(localStorage.getItem('expenseCache'));
if (cacheData && cacheData.lastSyncTime) {
const age = Date.now() - cacheData.lastSyncTime;
if (age > CACHE_MAX_AGE) {
console.log('Cache too old, clearing...');
expenseCache.clearCache();
expenseCache.refresh();
}
}
}
// Check on app load
checkCacheAge();
// In cache store
const CACHE_VERSION = 2; // Increment when schema changes
function checkCacheVersion() {
const cacheData = JSON.parse(localStorage.getItem('expenseCache'));
if (!cacheData || cacheData.version !== CACHE_VERSION) {
console.log('Cache version mismatch, clearing...');
clearCache();
// Set new version
localStorage.setItem('expenseCache', JSON.stringify({
version: CACHE_VERSION,
lastSyncTime: 0,
lastRecordId: 0
}));
}
}
// Check storage usage
if (navigator.storage && navigator.storage.estimate) {
navigator.storage.estimate().then(estimate => {
const percentUsed = (estimate.usage / estimate.quota) * 100;
console.log(`Storage: ${percentUsed.toFixed(2)}% used`);
if (percentUsed > 90) {
console.warn('Storage almost full, clearing old cache...');
clearOldestRecords();
}
});
}
function clearOldestRecords() {
// Keep only most recent 100 records
expenseCache.records.update(records =>
records
.sort((a, b) => b.id - a.id)
.slice(0, 100)
);
}
console.log('localStorage keys:', Object.keys(localStorage));
// Should be [] or minimal
console.log('localStorage size:', localStorage.length);
// Should be 0 or very small
DevTools → Application → IndexedDB
- Check if database exists
- Check if tables are empty
// Refresh and watch console
location.reload();
// Should see:
// "Cache miss, fetching from Odoo..."
// "Fetched X records"
□ Data loads correctly
□ CRUD operations work
□ Sync happens
□ Offline mode works after re-caching
Solution 1: Force with DevTools
1. Open DevTools (F12)
2. Application tab
3. Clear storage section
4. Check all boxes
5. Click "Clear site data"
Solution 2: Use Private/Incognito
Open app in private browsing mode
- Fresh session, no cache
- Test functionality
Solution 3: Different Browser
Test in different browser
- Rules out browser-specific issues
Solution: Check Multiple Sources
// Clear all possible locations
localStorage.clear();
sessionStorage.clear();
indexedDB.deleteDatabase('odoo-pwa-db');
// Unregister service workers
navigator.serviceWorker.getRegistrations()
.then(regs => regs.forEach(reg => reg.unregister()));
// Clear all caches
caches.keys()
.then(keys => Promise.all(keys.map(k => caches.delete(k))));
Solution: Ensure Graceful Degradation
// In cache store, handle missing cache
function loadFromCache() {
try {
const cached = localStorage.getItem('expenseCache');
if (!cached) {
console.log('No cache, will fetch from Odoo');
return { records: [], lastRecordId: 0, lastSyncTime: 0 };
}
return JSON.parse(cached);
} catch (error) {
console.error('Error loading cache:', error);
return { records: [], lastRecordId: 0, lastSyncTime: 0 };
}
}
<script>
import { expenseCache, taskCache } from '$lib/stores';
async function clearAll() {
if (confirm('Clear all cached data? This cannot be undone.')) {
expenseCache.clearCache();
taskCache.clearCache();
alert('Cache cleared! Refreshing...');
location.reload();
}
}
async function clearExpenses() {
if (confirm('Clear expense cache?')) {
expenseCache.clearCache();
await expenseCache.refresh();
alert('Expense cache cleared!');
}
}
function getCacheInfo() {
const size = new Blob(Object.values(localStorage)).size;
const sizeKB = (size / 1024).toFixed(2);
return { count: localStorage.length, sizeKB };
}
</script>
<div class="settings">
<h2>Cache Management</h2>
<div class="cache-info">
<p>Items: {getCacheInfo().count}</p>
<p>Size: {getCacheInfo().sizeKB} KB</p>
<p>Last sync: {new Date($expenseCache.lastSync).toLocaleString()}</p>
</div>
<div class="actions">
<button on:click={clearExpenses}>Clear Expense Cache</button>
<button on:click={clearAll} class="danger">Clear All Cache</button>
</div>
</div>
<style>
.danger {
background: red;
color: white;
}
</style>
Before clearing:
□ Save any unsaved work
□ Note current state
□ Ensure internet connection
□ Close duplicate tabs
After clearing:
□ localStorage is empty
□ IndexedDB is cleared
□ Service worker cache cleared
□ Fresh data loaded
□ Functionality tested
□ Sync works correctly
□ Offline mode re-enabled (after cache rebuilt)
function clearCache() {
const message = `
This will clear all cached data.
You'll need to re-download everything from Odoo.
Continue?
`;
if (confirm(message)) {
// Proceed
}
}
async function clearAndRefresh() {
alert('Clearing cache...');
localStorage.clear();
alert('Fetching fresh data...');
await expenseCache.refresh();
alert('Done! Cache rebuilt.');
}
function clearCache() {
console.log('Before clear:', {
localStorage: localStorage.length,
records: $expenseCache.length
});
localStorage.clear();
expenseCache.clearCache();
console.log('After clear:', {
localStorage: localStorage.length,
records: $expenseCache.length
});
}
/clear-cache - Clear all cached data/fix-sync - If sync issues persist/test-connection - Test after clearing/troubleshoot - For other issues/help - Full documentation// Copy-paste into console
localStorage.clear();
sessionStorage.clear();
indexedDB.databases().then(dbs =>
dbs.forEach(db => indexedDB.deleteDatabase(db.name))
);
navigator.serviceWorker.getRegistrations().then(regs =>
regs.forEach(reg => reg.unregister())
);
caches.keys().then(keys =>
keys.forEach(key => caches.delete(key))
);
location.reload(true);
localStorage.removeItem('expenseCache');
expenseCache.refresh();
const cache = JSON.parse(localStorage.getItem('expenseCache'));
cache.lastSyncTime = 0;
cache.lastRecordId = 0;
localStorage.setItem('expenseCache', JSON.stringify(cache));
expenseCache.refresh();