Skip to content

Commit

Permalink
feat(cache): better restrict acceptable type of RemoteStateCache; add…
Browse files Browse the repository at this point in the history
… default serde at context level
  • Loading branch information
uladkasach committed Nov 25, 2022
1 parent aae5fcf commit a15fd1e
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 70 deletions.
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/node_modules": false
}
}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ const { withRemoteStateQueryCaching, withRemoteStateMutationRegistration } = cre
```


note, in this particular example we're using [simple-localstorage-cache](https://github.com/ehmpathy/simple-localstorage-cache), but you can use any cache which works with [with-simple-caching](https://github.com/ehmpathy/with-simple-caching), for example
note, in this particular example we're using [simple-localstorage-cache](https://github.com/ehmpathy/simple-localstorage-cache), but you can use any async cache which works with [with-simple-caching](https://github.com/ehmpathy/with-simple-caching), for example
- [simple-on-disk-caching](https://github.com/ehmpathy/simple-on-disk-cache) for s3 and mounted persistance
- [simple-dynamodb-caching](https://github.com/ehmpathy/simple-dynamodb-cache) for dynamodb persistance
- [simple-localstorage-caching](https://github.com/ehmpathy/simple-localstorage-cache) for browser localstorage persistance
- [simple-in-memory-caching](https://github.com/ehmpathy/simple-in-memory-cache) for in-memory persistance
- etc


Expand Down
142 changes: 116 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@
"jest": "^27.0.0",
"prettier": "^2.0.4",
"simple-in-memory-cache": "^0.3.0",
"simple-on-disk-cache": "^1.1.0",
"simple-on-disk-cache": "^1.3.1",
"ts-jest": "^27.0.0",
"typescript": "^4.5.5",
"uuid": "^3.3.3"
},
"dependencies": {
"@types/sha.js": "^2.4.0",
"sha.js": "^2.4.11",
"type-fns": "^0.4.1",
"with-simple-caching": "^0.9.5"
"with-simple-caching": "^0.10.1"
}
}
4 changes: 2 additions & 2 deletions src/RemoteStateCache.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { SimpleCache } from 'with-simple-caching';
import { SimpleAsyncCache } from 'with-simple-caching';

/**
* any simple-cache can be used as a remote-state-cache as long as it also implements a `keys` method which returns all of the currently valid keys for the cache
*
* relevance
* - in order to trigger updates/invalidations, we need to expose all of the keys the user may want to choose from to the user
*/
export interface RemoteStateCache<CV extends any> extends SimpleCache<CV> {
export interface RemoteStateCache extends SimpleAsyncCache<string> {
keys: () => Promise<string[]> | string[];
}
Loading

0 comments on commit a15fd1e

Please sign in to comment.