Extend localStorage to Support Automatic Key Expiry and TTL

Build a wrapper around the native localStorage API that adds TTL (Time-to-Live) support. When setting an item, accept an optional expiry time in milliseconds. When getting an item, automatically check if it has expired and return null (while also purging the stale entry) if it has. Implement setItem, getItem, and removeItem. This pattern is widely used for client-side caching of API responses, user sessions, and feature flags.

Examples
Input: []
Output:
Hints

Extend localStorage to Support Automatic Key Expiry and TTL

Build a wrapper around the native localStorage API that adds TTL (Time-to-Live) support. When setting an item, accept an optional expiry time in milliseconds. When getting an item, automatically check if it has expired and return null (while also purging the stale entry) if it has. Implement setItem, getItem, and removeItem. This pattern is widely used for client-side caching of API responses, user sessions, and feature flags.