https://github.com/miguelzacca/super-sessionstorage
Implementation of improved window.sessionStorage for server, Type-Safe, and TTL cache system.
https://github.com/miguelzacca/super-sessionstorage
cache inmemory parse parsed server sessionstorage storage super ttl ttl-cache type-safe typesafe window
Last synced: 4 months ago
JSON representation
Implementation of improved window.sessionStorage for server, Type-Safe, and TTL cache system.
- Host: GitHub
- URL: https://github.com/miguelzacca/super-sessionstorage
- Owner: miguelzacca
- License: mit
- Created: 2024-08-05T01:31:40.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-04T20:08:54.000Z (over 1 year ago)
- Last Synced: 2025-10-13T16:44:36.539Z (8 months ago)
- Topics: cache, inmemory, parse, parsed, server, sessionstorage, storage, super, ttl, ttl-cache, type-safe, typesafe, window
- Language: TypeScript
- Homepage:
- Size: 68.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Super sessionStorage
Implementation of improved `window.sessionStorage` for server, `Type-Safe`, and TTL cache system.
it works without the need for a `window`. Furthermore, super sessionstorage maintains the original types, avoiding the need to make conversions. (type-safe storage).
## Install
```bash
npm install super-sessionstorage
```
## Methods
- `setItem(key: string, value: T, customTTL?: number): void`
- `getItem(key: string): T | undefined`
- `key(index: number): string | undefined`
- `has(key: string): boolean`
- `includes(value: T): boolean`
- `clear(): void`
- `get length(): number`
- `removeItem(key: string): void`
## Options
- `stdTTL` default is infinity (seconds)
- `checkperiod` default is 60 (seconds)
## Strict Type
```js
const storage = new SuperSessionStorage({ /* options */ })
```
## Example
#### config.js:
```js
import { SuperSessionStorage } from 'super-sessionstorage'
export const storage = new SuperSessionStorage({ stdTTL: 3600 })
```
#### setItem:
```js
import { storage } from './config.js'
const myObject = {
test1: 123,
test2: [1, 2, '123'],
}
storage.setItem('example', myObject)
```
#### getItem:
```js
import { storage } from './config.js'
const example = storage.getItem('example')
console.log(example)
console.log(typeof example)
```
#### output:
```txt
{ test1: 123, test2: [1, 2, "123"] }
object
```
#### Strict Type:
```js
import { SuperSessionStorage } from 'super-sessionstorage'
type Item = { id: number; productName: string }
const storage = new SuperSessionStorage()
storage.setItem('example1', { id: '100', productName: 'test' })
// Error: Id should be number
```