Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Api calls caching via redis - Closes #484 #577

Merged
merged 66 commits into from
Jun 8, 2017

Conversation

SargeKhan
Copy link
Contributor

@SargeKhan SargeKhan commented May 11, 2017

This pull request introduces 2 new fields in config.json file.

  • Boolean type cacheEnabled field for enabling/disabling cache.
  • Object type cache field for specifying the configuration of Redis cache.

Closes #484

@SargeKhan SargeKhan self-assigned this May 11, 2017
@SargeKhan SargeKhan requested a review from karmacoma May 11, 2017 09:11
@karmacoma karmacoma changed the title Api calls caching via redis - #484 Api calls caching via redis - Closes #484 May 11, 2017
@karmacoma karmacoma changed the base branch from development to 0.9.0 May 15, 2017 12:50
Copy link
Contributor

@Isabello Isabello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking for the change to config.json to allow the flag to be toggled. Default option should be OFF or FALSE

@@ -13,6 +13,8 @@ var database = require(path.join(dirname, '/helpers', 'database.js'));
var genesisblock = require(path.join(dirname, '/genesisBlock.json'));
var Logger = require(dirname + '/logger.js');
var z_schema = require('../../helpers/z_schema.js');
var cache = require('../../helpers/cache.js');
Copy link
Contributor

@Isabello Isabello May 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this naming is confusing, is there a better way? Cache and cache requires...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, having cache and Cache variable might be confusing. I'll update it to something like cacheHelper.

@SargeKhan
Copy link
Contributor Author

@Isabello, I have those options in my config.json file, I'll push them and update the description of the pull request as well.

Isabello
Isabello previously approved these changes May 16, 2017
@Isabello
Copy link
Contributor

Thank you! Looks good. I will do another check over it in the morning

@@ -176,6 +176,24 @@ var middleware = {
} else {
next();
}
},
flushCache: function (logger, cache, req, res, next) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need req here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Express calls this function internally with (req, res, next) parameters. So, (based on my knowledge), we need to specify req parameter here.

config.json Outdated
@@ -21,6 +22,10 @@
"error"
]
},
"cache": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this below API? Or even inside API since caching is related to API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this would definitely make more sense. I'll update this bit. Thanks!

Copy link
Contributor

@Isabello Isabello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ensure that the config.json in test/ has the correct schema :)

MaciejBaj
MaciejBaj previously approved these changes Jun 6, 2017
@@ -15,3 +15,5 @@ stacktrace*
test/.coverage-unit
tmp
sftp-config.json
*.swp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine with me.

@@ -19,6 +20,7 @@ before_script:
- tar -zxvf lisk-node-Linux-x86_64.tar.gz
- cd test/lisk-js/; npm install; cd ../..
- cp test/config.json test/genesisBlock.json .
- redis-server --port 6380 &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good thanks

"redis": {
"host": "127.0.0.1",
"port": 6380,
"db": 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

schema/config.js Outdated
type: 'string'
}
}
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require these fields.

@@ -38,6 +38,9 @@ module.exports = {
topAccounts: {
type: 'boolean'
},
cacheEnabled: {
type: 'boolean'
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require this field

cache.setJsonForKey(key, value, function (err, status) {
expect(err).to.not.exist;
expect(status).to.equal('OK');
//this function doesn't accept a callback, so waiting 2 seconds before checking if the actions were completed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional cb should be ok, waiting on timeout makes tests fragile

@SargeKhan SargeKhan dismissed stale reviews from MaciejBaj and 4miners via 19fb17d June 6, 2017 17:02
modules/cache.js Outdated
if(!self.isReady()) { return; }
async.map(['/api/blocks*', '/api/transactions*'], function (pattern) {
Cache.prototype.onNewBlock = function (block, broadcast, cb) {
cb = cb ? cb: function () {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only call callback in one place so if (cb) { return cb(); } is more readable. If we want to keep current approach cb = cb || function () {}; is shorter and cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use cb in multiple places based on certain conditions in other functions. So, using the second approach which you suggested. But good advice. Thanks 👍

modules/cache.js Outdated
@@ -16,14 +21,28 @@ function Cache (cb, scope) {
setImmediate(cb, null, self);
}

/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**, globally

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants