-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add lru cache and block info pagination (#26)
Description --- Add pagination to all outpus/inputs/kernels. Add caching on the express server for this pagination requests. Motivation and Context --- How Has This Been Tested? --- Manually. What process can a PR reviewer use to test or verify this change? --- Go to some very heavy block and see that the request is fast and also lightweight. <!-- Checklist --> <!-- 1. Is the title of your PR in the form that would make nice release notes? The title, excluding the conventional commit tag, will be included exactly as is in the CHANGELOG, so please think about it carefully. --> Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify <!-- Does this include a breaking change? If so, include this line as a footer --> <!-- BREAKING CHANGE: Description what the user should do, e.g. delete a database, resync the chain -->
- Loading branch information
Showing
4 changed files
with
207 additions
and
10 deletions.
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
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 @@ | ||
class Cache { | ||
constructor(limit = 1000) { | ||
this.limit = limit; | ||
this.cache = new Map(); | ||
} | ||
|
||
set(key, value) { | ||
if (this.cache.size >= this.limit) { | ||
const firstItemKey = this.cache.keys().next().value; | ||
this.cache.delete(firstItemKey); | ||
} | ||
this.cache.set(key, value); | ||
} | ||
|
||
async get(func, args) { | ||
let cache_key = JSON.stringify(args); | ||
if (this.cache.has(cache_key)) { | ||
const temp = this.cache.get(cache_key); | ||
this.cache.delete(cache_key); | ||
this.cache.set(cache_key, temp); | ||
return temp; | ||
} | ||
let result = await func(args); | ||
console.log("Actual call", args); | ||
this.set(cache_key, result); | ||
return result; | ||
} | ||
} | ||
|
||
var cache = new Cache(); | ||
module.exports = cache; |
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