This repository has been archived by the owner on Feb 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Improved component caching #36
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
68d782e
Re-organize caching code to accommodate non-default caching strategies.
divmain 57aa4c0
Defer consumption of sequence if `next` value is a promise until prom…
divmain b2f9d0f
Implement an async cache mechanism with an intermediate synchronous c…
divmain e7cad8c
Expose API for integrating with third-party caching solutions.
divmain 8611327
Expose `Promise` to library consumers.
divmain 5cd9e89
Add tests for async cache mechanism.
divmain ed5ce35
Add note on cache value shape to README.
divmain File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
const Promise = require("bluebird"); | ||
|
||
const Renderer = require("./renderer"); | ||
const template = require("./template"); | ||
const { setCacheStrategy } = require("./sequence/cache"); | ||
|
||
|
||
module.exports = { | ||
render: jsx => new Renderer(jsx), | ||
template | ||
template, | ||
setCacheStrategy, | ||
Promise | ||
}; |
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,30 @@ | ||
const { isFunction } = require("lodash"); | ||
|
||
const defaultStrategy = require("./strategies/default"); | ||
const asyncStrategy = require("./strategies/async"); | ||
|
||
|
||
let cacheStrategy = defaultStrategy(); | ||
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. Would there ever be a scenario for having two rapscallion instances which would have differing cache strategies? You've got a global mutable singleton, which ties your hands a bit vs. maybe creating a cache object to initialize and pass to renderers... |
||
|
||
|
||
function getCachedSequence (sequence, node, sequenceFactory) { | ||
return cacheStrategy(sequence, node, sequenceFactory); | ||
} | ||
|
||
function setCacheStrategy (opts) { | ||
if (!isFunction(opts && opts.get) || !isFunction(opts && opts.set)) { | ||
throw new Error("Async cache strategy must be provided `get` and `set` options."); | ||
} | ||
cacheStrategy = asyncStrategy(opts); | ||
} | ||
|
||
function useDefaultCacheStrategy () { | ||
cacheStrategy = defaultStrategy(); | ||
} | ||
|
||
|
||
module.exports = { | ||
getCachedSequence, | ||
setCacheStrategy, | ||
useDefaultCacheStrategy | ||
}; |
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.
Are there any legitimate cases for ever wanting to cache a
val=null
?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.
Fortunately, no. Due to the internal representation of completed sequences, the cached values will be of type
Array<String|Integer>
. This wasn't always the case, but I moved in that direction awhile back to keep things easily serializable.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.
I should clarify the expected shape of the cache values in the docs, however! Thanks for pointing it out.