generated from apollographql/typescript-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added support to the `RESTDatasource` to be able to specify a custom cache set options type. The cache set options may need to be customized to include additional set options supported by the underlying key value cache implementation. --------- Co-authored-by: Hisham Ali <hisham@otofacts.com>
- Loading branch information
1 parent
9f9f8ac
commit 147f820
Showing
8 changed files
with
202 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
'@apollo/datasource-rest': minor | ||
--- | ||
|
||
Added support to the RESTDatasource to be able to specify a custom cache set options type. The cache set options may need to be customized to include additional set options supported by the underlying key value cache implementation. | ||
|
||
For example, if the [InMemoryLRUCache](https://github.com/apollographql/apollo-utils/blob/main/packages/keyValueCache/src/InMemoryLRUCache.ts) is being used to cache HTTP responses, then `noDisposeOnSet`, `noUpdateTTL`, etc cache options can be provided to the LRU cache: | ||
|
||
```typescript | ||
import { InMemoryLRUCache } from '@apollo/utils.keyvaluecache'; | ||
|
||
interface CustomCacheOptions { | ||
ttl?: number; | ||
noDisposeOnSet?: boolean; | ||
} | ||
|
||
class ExampleDataSource extends RESTDataSource<CustomCacheOptions> { | ||
override baseURL = 'https://api.example.com'; | ||
|
||
constructor() { | ||
super({ cache: new InMemoryLRUCache() }); | ||
} | ||
|
||
getData(id: number) { | ||
return this.get(`data/${id}`, { | ||
cacheOptions: { ttl: 3600, noDisposeOnSet: true }, | ||
}); | ||
} | ||
} | ||
``` |
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
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
Oops, something went wrong.