This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 455
Api calls caching via redis - Closes #484 #577
Merged
Merged
Changes from 57 commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
a935984
added caching functionality basic structure
SargeKhan c3f6d5e
ignore swap files created by vi
SargeKhan 5e18420
refined cache logic, created express middleware for caching
SargeKhan 527daaa
updated router.map to support middleware, added caching for getBroadhash
SargeKhan 739aab8
updated cache error handling, added unit tests for cache module
SargeKhan 3843a40
removed some comments
SargeKhan 2289adc
Merge branch '0.9.0' into 484-api_calls_caching
SargeKhan 9ce548d
added cache options in config.json
SargeKhan 7711523
Merge branch '484-api_calls_caching' of github.com:SargeKhan/lisk int…
SargeKhan 232b40e
added one more cache test
SargeKhan 6ed4fc6
added db flushing middleware, updated error handling
SargeKhan 9258f38
updated cache tests to skip when cacheEnable=false
SargeKhan 9aaaa32
updated cache helper name
SargeKhan 6256cb2
updated config.json, added middlware
SargeKhan 2427a94
added cache config to test config file
SargeKhan b4be92b
Updated cache configuration key in tests
SargeKhan 541b2a3
added space, removed router.map changes
SargeKhan 5b9eb6d
added test cases for blocks, transaction and delegates GET caching
SargeKhan f7f17db
added cache flushing on new block, delegate trs and round finish
SargeKhan cf023de
refactored cache tests, closed cache connection on tests completion
SargeKhan 1713b90
added test for caching flushing on new block
SargeKhan 8b6cffa
Merge branch '484-api_calls_caching' of github.com:SargeKhan/lisk int…
SargeKhan faa2192
removed flushCache middleware
SargeKhan ffe39ac
reverted router.map
SargeKhan a6f11e0
added comments, closed connection on cleanup
SargeKhan aed1314
added test for new round
SargeKhan 2ad988b
updated tests to resolve successfully
SargeKhan 6e95945
add redis service on travis
SargeKhan 8b8ca31
removed itIfCacheenabled, set cacheEnabled to true
SargeKhan 8cf680f
updated listeners to del their respective subset of cache entries
SargeKhan f2e6ca3
fixed test completion bug
SargeKhan 1d98768
updated logs on cache clearing
SargeKhan 044eb11
disabled cache while syncing, reordered funcs in modules/cache
SargeKhan 1c91295
added further unit test cases
SargeKhan 07e0a46
resolved module conflicts
SargeKhan ae3111f
fixed mispellings
SargeKhan 48b0457
updated redis server port
SargeKhan bddbd89
removed cache monitoring
SargeKhan 4f67bf6
updated log messages
SargeKhan a8fb6b9
updating travis redis port
SargeKhan 06c9b3d
updating travis redis to run in background
SargeKhan 44afeff
disable all redis features when syncing
SargeKhan 6dcf5d6
updated redis config structure
SargeKhan 9998671
test cache config. updated
SargeKhan 3044b15
added test cases for disabling cache when syncing
SargeKhan ebfddd0
fixed typo
SargeKhan a2bf761
updated callbackCalled to a more descriptive name
SargeKhan d9a3978
refactored to remove nesting level
SargeKhan b9500a4
wait for cache.quit to complete before proceeding
SargeKhan ecc6fab
triggered clear cache after saving delegate trs in block
SargeKhan edac1ce
fixed inconsistent name
SargeKhan 096c47d
fixed indentation
SargeKhan 03a2c8d
disabled cache on default
SargeKhan bd6ad04
replaced err with null
SargeKhan a2ba561
Merge branch '0.9.0' into 484-api_calls_caching
4miners 2b4507e
updated cache logs status from info to debug
SargeKhan aa098d2
Merge branch '484-api_calls_caching' of github.com:SargeKhan/lisk int…
SargeKhan 5bc07e8
required redis related fields in schema
SargeKhan 488d55b
add callbacks for all events listners in cache module
SargeKhan 79cc021
add callbacks for all events listners in cache module
SargeKhan 19fb17d
remove timeouts, use callbacks for events
SargeKhan 029ff44
updated default cb definition
SargeKhan 98aee83
removed orphan comment
SargeKhan 70539a2
added docs for functions
SargeKhan 7947002
added some missing comments
SargeKhan 1d5c273
Merge branch '0.9.0' into 484-api_calls_caching
4miners File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ stacktrace* | |
test/.coverage-unit | ||
tmp | ||
sftp-config.json | ||
*.swp | ||
*.swo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ cache: | |
- node_modules | ||
services: | ||
- postgresql | ||
- redis-server | ||
addons: | ||
postgresql: '9.6' | ||
install: | ||
|
@@ -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 & | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good thanks |
||
- node app.js &> .app.log & | ||
notifications: | ||
webhooks: https://coveralls.io/webhook?repo_token=l6rLvPBYHIwA92FQQmCUUTLI4zPuS4r5C | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
"consoleLogLevel": "info", | ||
"trustProxy": false, | ||
"topAccounts": false, | ||
"cacheEnabled": false, | ||
"db": { | ||
"host": "localhost", | ||
"port": 5432, | ||
|
@@ -21,6 +22,13 @@ | |
"error" | ||
] | ||
}, | ||
"redis": { | ||
"host": "127.0.0.1", | ||
"port": 6380, | ||
"db": 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good |
||
"user": "", | ||
"password": "" | ||
}, | ||
"api": { | ||
"enabled": true, | ||
"access": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
var redis = require('redis'); | ||
|
||
module.exports.connect = function (cacheEnabled, config, logger, cb) { | ||
var isRedisLoaded = false; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That line can be removed |
||
if (!cacheEnabled) { | ||
return cb(null, { cacheEnabled: cacheEnabled, client: null }); | ||
} | ||
|
||
var client = redis.createClient(config); | ||
|
||
client.on('connect', function () { | ||
logger.info('App connected with redis server'); | ||
|
||
if (!isRedisLoaded) { | ||
isRedisLoaded = true; | ||
return cb(null, { cacheEnabled: cacheEnabled, client: client }); | ||
} | ||
}); | ||
|
||
client.on('error', function (err) { | ||
logger.error('Redis:', err); | ||
// Only throw an error if cache was enabled in config but were unable to load it properly | ||
if (!isRedisLoaded) { | ||
isRedisLoaded = true; | ||
return cb('Unable to connect to redis server', { cacheEnabled: cacheEnabled, client: null }); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fo what we need those ignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my editor generates while editing, I don't think we'd be needing these file types. So, I think it's safe to ignore them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fine with me.