Skip to content

Commit 517636d

Browse files
author
dustin deus
committed
improve
1 parent c769867 commit 517636d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ const datasource = new (class MoviesAPI extends HTTPDataSource {
8484
headers: {
8585
'X-Foo': 'bar',
8686
},
87+
requestCache: {
88+
maxTtl: 1000 * 60 * 10, // 10min, will respond for 10min with the cached result (updated every 10min)
89+
maxTtlIfError: 1000 * 60 * 30, // 30min, will respond in an error case with the cached response (for further 20min)
90+
},
8791
})
8892
}
8993
})()

src/http-data-source.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export interface HTTPDataSourceOptions {
5353

5454
function apolloKeyValueCacheToKeyv(cache: KeyValueCache): Store<string> {
5555
return {
56-
async get(key: string) {
57-
return await cache.get(key)
56+
get(key: string) {
57+
return cache.get(key)
5858
},
5959
clear() {
6060
throw new Error('clear() method is not supported by apollo key value cache')
@@ -67,8 +67,8 @@ function apolloKeyValueCacheToKeyv(cache: KeyValueCache): Store<string> {
6767

6868
return true
6969
},
70-
async set(key: string, value: string, ttl?: number) {
71-
return await cache.set(key, value, {
70+
set(key: string, value: string, ttl?: number) {
71+
return cache.set(key, value, {
7272
ttl,
7373
})
7474
},

0 commit comments

Comments
 (0)