-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Unify and cleanup cache.js. #694
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9bc636d
Cleanup, remove unusued methods and unify cache.js.
nlutsenko 49a4b74
Fix missing return type on requiredParameter.js.
nlutsenko daa5f11
Remove 'database' field from request and make all database requests g…
nlutsenko d30c3e9
Remove useless method in index.js.
nlutsenko 768a781
Fix wrong order of resetting data in test helper.
nlutsenko 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
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,45 +1,35 @@ | ||
export var apps = {}; | ||
export var stats = {}; | ||
export var isLoaded = false; | ||
export var users = {}; | ||
/** @flow weak */ | ||
|
||
export function getApp(app, callback) { | ||
if (apps[app]) return callback(true, apps[app]); | ||
return callback(false); | ||
export function CacheStore<KeyType, ValueType>() { | ||
let dataStore: {[id:KeyType]:ValueType} = {}; | ||
return { | ||
get: (key: KeyType): ValueType => { | ||
return dataStore[key]; | ||
}, | ||
set(key: KeyType, value: ValueType): void { | ||
dataStore[key] = value; | ||
}, | ||
remove(key: KeyType): void { | ||
delete dataStore[key]; | ||
}, | ||
clear(): void { | ||
dataStore = {}; | ||
} | ||
}; | ||
} | ||
|
||
export function updateStat(key, value) { | ||
stats[key] = value; | ||
} | ||
|
||
export function getUser(sessionToken) { | ||
if (users[sessionToken]) return users[sessionToken]; | ||
return undefined; | ||
} | ||
|
||
export function setUser(sessionToken, userObject) { | ||
users[sessionToken] = userObject; | ||
} | ||
|
||
export function clearUser(sessionToken) { | ||
delete users[sessionToken]; | ||
} | ||
const apps = CacheStore(); | ||
const users = CacheStore(); | ||
|
||
//So far used only in tests | ||
export function clearCache() { | ||
apps = {}; | ||
stats = {}; | ||
users = {}; | ||
export function clearCache(): void { | ||
apps.clear(); | ||
users.clear(); | ||
} | ||
|
||
export default { | ||
apps, | ||
stats, | ||
isLoaded, | ||
getApp, | ||
updateStat, | ||
clearUser, | ||
getUser, | ||
setUser, | ||
users, | ||
clearCache, | ||
CacheStore | ||
}; |
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,2 +1,2 @@ | ||
/* @flow */ | ||
export default (errorMessage: string) => {throw errorMessage} | ||
/** @flow */ | ||
export default (errorMessage: string): any => { throw errorMessage } |
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
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.
Use es6 style { masterKey, collectionPrefix...}