-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
49 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
# idmp/node-fs | ||
# idmp/browser-storage | ||
|
||
## Useage | ||
## Usage | ||
|
||
```typescript | ||
import idmp from 'idmp' | ||
import storageWrap, { getCacheKey } from 'idmp/browser-storage' | ||
|
||
const localStorageIdmp = storageWrap( | ||
idmp, | ||
'localStorage' /* default is 'sessionStorage' */, | ||
) | ||
|
||
const getUserDataWithlocalStorageIdmp = (userId: string) => | ||
localStorageIdmp( | ||
`getUserDataWithlocalStorageIdmp${userId}`, | ||
() => getUserData(userId), | ||
{ | ||
maxAge: 5000, | ||
}, | ||
) | ||
|
||
getUserDataWithlocalStorageIdmp('123').then((data) => { | ||
const lsIdmp = storageWrap(idmp, 'localStorage') | ||
|
||
const getUserDataWithLsIdmp = (userId: string) => | ||
lsIdmp(`getUserDataWithLsIdmp${userId}`, () => getUserData(userId), { | ||
maxAge: 5000, | ||
}) | ||
|
||
getUserDataWithLsIdmp('123').then((data) => { | ||
console.log(data) | ||
}) | ||
``` | ||
|
||
Cache data will be stored in `localStorage / sessionStorage` temporary directory and follow the same cache options as `idmp`. | ||
If the data is in the memory, it is read from the memory first. If it is not in the memory, it is read from the `localStorage / sessionStorage`. If the cache validity period expires, it will be read from the remote end. | ||
|
||
## Notice | ||
|
||
Data persistence only supports string type `globalKey` and data structures that can be serialized by `JSON.stringify` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
{ | ||
"rewrites": [ | ||
{"source": "/(.*)", "destination": "/"} | ||
] | ||
"rewrites": [{ "source": "/(.*)", "destination": "/" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters