Home > widget-integration > FilterStorageHelper > clearLocalStorageByPrefix

FilterStorageHelper.clearLocalStorageByPrefix() method

Clears all items from localStorage with a specific prefix.

Removes all local storage keys that start with the given prefix. Useful for clearing all filter-related persistent storage at once.

Signature:

clearLocalStorageByPrefix(prefix: string): void;

Parameters

Parameter

Type

Description

prefix

string

The key prefix to match (e.g., 'boost-sd-filter-')

Returns:

void

Remarks

Iterates through all storage keys to find matches. Performance scales with total number of keys in storage. Use carefully as this affects persistent storage across sessions.

Example

Override to add confirmation for critical prefixes:

clearLocalStorageByPrefix(prefix) {
  if (this.isCriticalPrefix(prefix)) {
    // Log before clearing critical storage
    this.logCriticalStorageClear(prefix);
  }
  super.clearLocalStorageByPrefix(prefix);
}