-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLDR-16048 New forum post window sometimes disappears #2821
Merged
Merged
Changes from all commits
Commits
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* cldrCache: a simple least-recently-used cache for the Survey Tool front end | ||
* | ||
* Based partly on: https://stackoverflow.com/questions/996505/lru-cache-implementation-in-javascript | ||
* post by odinho - Velmont | ||
*/ | ||
export class LRU { | ||
constructor(max = 100) { | ||
this._max = max; | ||
this._cache = new Map(); | ||
} | ||
|
||
clear() { | ||
this._cache.clear(); | ||
} | ||
|
||
get(key) { | ||
const val = this._cache.get(key); | ||
if (val) { | ||
// delete and set again so it's most recent | ||
this._cache.delete(key); | ||
this._cache.set(key, val); | ||
} | ||
return val; | ||
} | ||
|
||
set(key, val) { | ||
if (this._cache.has(key)) { | ||
// delete before setting again so it's most recent | ||
this._cache.delete(key); | ||
} else if (this._cache.size == this._max) { | ||
this._cache.delete(this._oldest()); | ||
} | ||
this._cache.set(key, val); | ||
} | ||
|
||
_oldest() { | ||
// Iteration happens in insertion order (chronologically), so the first is the oldest | ||
// Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map | ||
return this._cache.keys().next().value; | ||
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. didn't know that, nice! |
||
} | ||
} |
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.
makes sense and is clear.
there's probably more places that could use caching, could use a package such as https://github.com/tusharf5/runtime-memcache (linked from the SO comment)
also https://www.npmjs.com/package/sls-cache can use the localstorage, which gives us a persistent cache between browser access. Could be good for truly readonly data such as xpath hash to xpath string.