Home > widget-integration > FilterStorageHelper > clearSessionStorageByPrefix

FilterStorageHelper.clearSessionStorageByPrefix() method

Clears all items from sessionStorage with a specific prefix.

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

Signature:

clearSessionStorageByPrefix(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, not just matching keys.

Example

Override to add bulk clear tracking:

clearSessionStorageByPrefix(prefix) {
  const keyCount = this.countKeysWithPrefix('session', prefix);
  super.clearSessionStorageByPrefix(prefix);
  this.analytics.track('bulk_storage_clear', {
    type: 'session',
    prefix,
    keysCleared: keyCount
  });
}