Skip to content

Commit

Permalink
Merge ea16f5d into c8bc953
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Nassri committed Mar 13, 2019
2 parents c8bc953 + ea16f5d commit 87b67f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ const app = new App({
})
```

> **NOTE**: an optional `expiry` parameter is passed to `cache.set`, useful for further automation of your cache mechanism
> _e.g. auto purge values after expiry is elapsed._
```js
const app = new App({
id: APP_ID,
privateKey: PRIVATE_KEY,
cache: {
get (key) {
return CACHE[key]
},
set (key, value, expiry) {
CACHE[key] = value

const timeout = (new Date(expiry)).getTime() - (new Date()).getTime();

setTimeout(() => delete CACHE[key], timeout)
}
}
})
```

## Using with GitHub Enterprise

The `baseUrl` option can be used to override default GitHub's `https://api.github.com`:
Expand Down
4 changes: 3 additions & 1 deletion lib/get-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ module.exports = getCache
const LRU = require('lru-cache')

function getCache () {
return new LRU({
const lru = new LRU({
// cache max. 15000 tokens, that will use less than 10mb memory
max: 15000,
// Cache for 1 minute less than GitHub expiry
maxAge: 1000 * 60 * 59
})

return { get: (key) => lru.get(key), set: (key, token) => lru.set(key, token) }
}
2 changes: 1 addition & 1 deletion lib/get-installation-access-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function getInstallationAccessToken (state, { installationId }) {
authorization: `bearer ${getSignedJsonWebToken(state)}`
}
}).then(response => {
state.cache.set(installationId, response.data.token)
state.cache.set(installationId, response.data.token, response.data.expires_at)
return response.data.token
})
}

0 comments on commit 87b67f2

Please sign in to comment.