https://github.com/ehmpathy/simple-localstorage-cache
A simple local-storage cache with time based expiration policies
https://github.com/ehmpathy/simple-localstorage-cache
Last synced: 6 months ago
JSON representation
A simple local-storage cache with time based expiration policies
- Host: GitHub
- URL: https://github.com/ehmpathy/simple-localstorage-cache
- Owner: ehmpathy
- License: mit
- Created: 2023-07-16T04:48:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-16T06:47:56.000Z (over 2 years ago)
- Last Synced: 2025-06-03T16:19:53.963Z (7 months ago)
- Language: TypeScript
- Size: 554 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# simple-localstorage-cache
A simple local-storage cache with time based expiration policies
# features
- simplicity: `get`, `set`, and `keys` with an intuitive, pit-of-success, implementation
- interoperability: fulfills the standard [SimpleAsyncCache](https://github.com/ehmpathy/with-simple-caching/blob/main/src/domain/SimpleCache.ts#L9-L15) interface
- can be used with
- [with-simple-caching](https://github.com/ehmpathy/with-simple-caching)
- [cache-dao-generator](https://github.com/ehmpathy/simple-cache-dao)
- garbage collection: automatically removes expired keys from local-storage to free up space
# install
```
npm install simple-localstorage-cache
```
# use
### create a cache
```ts
const cache = createCache({ namespace: 'super-awesome-feature' });
```
### set to the cache
```ts
await cache.set('answer', 42);
```
***ℹ️ note: if you'd like an item to never expire, set the expiration time to `null` or `Infinity`***
### get from the cache
```ts
await cache.get('answer'); // 42
```