Skip to content

Commit 410b33b

Browse files
authored
1.1.6 12: fix ttl vs options obj (cvburgess#16)
- Fix issue setting TTL on cache requests [cvburgess#15]
1 parent ca23b63 commit 410b33b

File tree

5 files changed

+43
-20
lines changed

5 files changed

+43
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.1.6 - 05-04-2019
4+
5+
- Fix issue setting TTL on cache requests [#15]
6+
37
## v0.1.5 - 28-02-2019
48

59
- Update dependencies to resolve cache TTL issue [#12]

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ And the peer dependencies (if you do not have them already): `npm i knex graphql
1616
const Knex = require("knex");
1717
const { SQLDataSource } = require("datasource-sql");
1818

19-
const MINUTE = 60 * 1000;
19+
const MINUTE = 60;
2020

2121
const knex = Knex({
2222
client: "pg",
@@ -89,21 +89,21 @@ SQLCache leverages Apollo's caching strategy to save results between requests an
8989

9090
This method accepts two parameters:
9191

92-
`getCached(knexQuery, ttlInMilliseconds)`
92+
`getCached(knexQuery, ttlInSeconds)`
9393

9494
- `knexQuery`: <knexObject> A knex object that has not been then'd
95-
- `ttlInMilliseconds`: <Number> number of milliseconds to keep cached results
95+
- `ttlInSeconds`: <Number> number of seconds to keep cached results
9696

9797
### Why not both?
9898

9999
To leverage caching _*and*_ batching for a query, use the method `getCachedAndBatched` which wraps both methods.
100100

101101
This method accepts the same two params as `getCached`:
102102

103-
`getBatchedAndCached(knexQuery, ttlInMilliseconds)`
103+
`getBatchedAndCached(knexQuery, ttlInSeconds)`
104104

105105
- `knexQuery`: <knexObject> A knex object that has not been then'd
106-
- `ttlInMilliseconds`: <Number> number of milliseconds to keep cached results
106+
- `ttlInSeconds`: <Number> number of seconds to keep cached results
107107

108108
From the example in the usage section above:
109109

SQLCache.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SQLCache {
2121
return this.cache.get(cacheKey).then(entry => {
2222
if (entry) return Promise.resolve(entry);
2323
return query.then(rows => {
24-
if (rows) this.cache.set(cacheKey, rows, ttl);
24+
if (rows) this.cache.set(cacheKey, rows, { ttl });
2525
return Promise.resolve(rows);
2626
});
2727
});
@@ -37,7 +37,7 @@ class SQLCache {
3737
.load(queryString)
3838
.then(result => result && result.rows)
3939
.then(rows => {
40-
if (rows) this.cache.set(cacheKey, rows, ttl);
40+
if (rows) this.cache.set(cacheKey, rows, { ttl });
4141
return Promise.resolve(rows);
4242
});
4343
});

package-lock.json

Lines changed: 31 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "datasource-sql",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "SQL DataSource for Apollo GraphQL projects",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)