Browse Source

invalidate cache after clear

imwald
Silberengel 3 days ago
parent
commit
2b9ead6568
  1. 1280
      package-lock.json
  2. 2
      package.json
  3. 7
      src/components/CacheRelaysSetting/index.tsx
  4. 15
      src/services/client.service.ts

1280
package-lock.json generated

File diff suppressed because it is too large Load Diff

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "jumble-imwald", "name": "jumble-imwald",
"version": "16.1.2", "version": "16.1.3",
"description": "A user-friendly Nostr client focused on relay feed browsing and relay discovery, forked from Jumble", "description": "A user-friendly Nostr client focused on relay feed browsing and relay discovery, forked from Jumble",
"private": true, "private": true,
"type": "module", "type": "module",

7
src/components/CacheRelaysSetting/index.tsx

@ -32,6 +32,7 @@ import { showPublishingFeedback, showSimplePublishSuccess, showPublishingError }
import { CloudUpload, Loader, Trash2, RefreshCw, Database, WrapText, Search, X, TriangleAlert, Terminal, XCircle } from 'lucide-react' import { CloudUpload, Loader, Trash2, RefreshCw, Database, WrapText, Search, X, TriangleAlert, Terminal, XCircle } from 'lucide-react'
import { Input } from '@/components/ui/input' import { Input } from '@/components/ui/input'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
import client from '@/services/client.service'
import indexedDb from '@/services/indexed-db.service' import indexedDb from '@/services/indexed-db.service'
import postEditorCache from '@/services/post-editor-cache.service' import postEditorCache from '@/services/post-editor-cache.service'
import { StorageKey } from '@/constants' import { StorageKey } from '@/constants'
@ -262,10 +263,16 @@ export default function CacheRelaysSetting() {
// Clear post editor cache // Clear post editor cache
postEditorCache.clearPostCache({}) postEditorCache.clearPostCache({})
// Clear in-memory caches so profile pics and reactions work after clear
client.clearInMemoryCaches()
// Reload cache info // Reload cache info
await loadCacheInfo() await loadCacheInfo()
toast.success(t('Cache cleared successfully')) toast.success(t('Cache cleared successfully'))
// Reload the app so it re-fetches profiles and relay lists from the network.
// Without this, missing IndexedDB + stale in-memory state can break reactions and avatars.
setTimeout(() => window.location.reload(), 1500)
} catch (error) { } catch (error) {
logger.error('Failed to clear cache', { error }) logger.error('Failed to clear cache', { error })
toast.error(t('Failed to clear cache')) toast.error(t('Failed to clear cache'))

15
src/services/client.service.ts

@ -1625,6 +1625,21 @@ class ClientService extends EventTarget {
this.relayListRequestCache.delete(pubkey) this.relayListRequestCache.delete(pubkey)
} }
/**
* Clear all in-memory caches. Call this after IndexedDB/cache clear so that
* subsequent fetches go to the network instead of serving stale in-memory data.
* Fixes missing profile pics and broken reactions after "Clear cache" on mobile.
*/
clearInMemoryCaches(): void {
this.replaceableEventCacheMap.clear()
this.relayListRequestCache.clear()
this.eventDataLoader.clearAll()
this.replaceableEventFromBigRelaysDataloader.clearAll()
this.trendingNotesCache = null
this.followingFavoriteRelaysCache?.clear()
logger.info('[ClientService] In-memory caches cleared')
}
async fetchRelayList(pubkey: string): Promise<TRelayList> { async fetchRelayList(pubkey: string): Promise<TRelayList> {
// Deduplicate concurrent requests for the same pubkey's relay list // Deduplicate concurrent requests for the same pubkey's relay list
const existingRequest = this.relayListRequestCache.get(pubkey) const existingRequest = this.relayListRequestCache.get(pubkey)

Loading…
Cancel
Save