Skip to content

Commit

Permalink
flushing http cache (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
iambeone authored Feb 17, 2020
1 parent de8eb24 commit e16df1c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/source/cosmosV0-source.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { RESTDataSource } = require('apollo-datasource-rest')
const { RESTDataSource, HTTPCache } = require('apollo-datasource-rest')
const { InMemoryLRUCache } = require('apollo-server-caching')
const BigNumber = require('bignumber.js')
const _ = require('lodash')
const { encodeB32, decodeB32, pubkeyToAddress } = require('../tools')
Expand All @@ -17,11 +18,22 @@ class CosmosV0API extends RESTDataSource {
this.setReducers()
}

initialize(config) {
this.context = config.context
// manually set cache to checking it
this.cache = new InMemoryLRUCache()
this.httpCache = new HTTPCache(this.cache, this.httpFetch)
}

setReducers() {
this.reducers = require('../reducers/cosmosV0-reducers')
}

async getRetry(url, intent = 0) {
// check cache size, and flush it if it's bigger than something
if ((await this.cache.getTotalSize()) > 100000) {
await this.cache.flush()
}
// cleareing memoizedResults
this.memoizedResults.clear()
try {
Expand Down

0 comments on commit e16df1c

Please sign in to comment.