-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Why: * Resolve is an expensive API call This change addresses the need by: * Cache results of last evaluation.
- Loading branch information
Showing
4 changed files
with
66 additions
and
4 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,20 @@ | ||
var uri = require('url'); | ||
|
||
function memoizeLastCall(func) { | ||
var lastArg1 = -1; | ||
var lastArg2 = -1; | ||
var lastResult = null; | ||
return function() { | ||
//return func.apply(null, arguments); | ||
if (lastArg1 === arguments[0] && lastArg2 === arguments[1]) { | ||
return lastResult; | ||
} else { | ||
lastResult = func.apply(null, arguments); | ||
lastArg1 = arguments[0]; | ||
lastArg2 = arguments[1]; | ||
return lastResult; | ||
} | ||
}; | ||
} | ||
|
||
module.exports = memoizeLastCall(uri.resolve); |
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