Skip to content

Add clearAll() method to CacheManager #420

@nogringo

Description

@nogringo

Feature Request

User Story

As a Flutter developer using NDK
I want to clear all cached data with a single method call
So that I can easily provide a "Clear cache" button to users without
needing to know the internal structure of the cache

Acceptance Criteria

  • Add a clearAll() method to the CacheManager abstract class
  • The method should clear all cached data (events, user relay lists, relay
    sets, contact lists, metadatas, nip05s, filter fetched range records)
  • Implementations (MemCacheManager, SembastCacheManager, etc.) should
    implement this method

Alternatives Considered

Currently I call each removeAll* method individually:

final cache = ndk.config.cache;                                               
await cache.removeAllEvents();                                                
await cache.removeAllUserRelayLists();                                        
await cache.removeAllRelaySets();                                             
await cache.removeAllContactLists();                                          
await cache.removeAllMetadatas();                                             
await cache.removeAllNip05s();                                                
await cache.removeAllFilterFetchedRangeRecords();

This works but is verbose and requires updating client code if new cache types
are added in the future.

Additional Context

Proposed API:

abstract class CacheManager {                                                 
  // ... existing methods ...                                                 
                                                                              
  /// Clears all cached data                                                  
  Future<void> clearAll();                                                    
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions