-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mensa and index: use the reimplemented Mensa API which now uses the s…
…ame json format as the THI API
- Loading branch information
Showing
4 changed files
with
109 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import MemoryCache from './memory-cache' | ||
import LocalStorageCache from './localstorage-cache' | ||
|
||
const CACHE_NAMESPACE = 'reimplemented-api-client' | ||
const CACHE_TTL = 10 * 60 * 1000 | ||
|
||
const KEY_GET_MENSA_PLAN = 'getMensaPlan' | ||
|
||
let cache | ||
if (typeof localStorage === 'undefined') { | ||
cache = new MemoryCache({ | ||
ttl: CACHE_TTL | ||
}) | ||
} else { | ||
cache = new LocalStorageCache({ | ||
namespace: CACHE_NAMESPACE, | ||
ttl: CACHE_TTL | ||
}) | ||
} | ||
|
||
export async function getMensaPlan () { | ||
let res = cache.get(KEY_GET_MENSA_PLAN) | ||
if (!res) { | ||
res = await fetch('/api/mensa').then(res => res.json()) | ||
} | ||
|
||
cache.set(KEY_GET_MENSA_PLAN, res) | ||
|
||
return res.data | ||
} |
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
9d518a4
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.
ref #7