mirror of
https://github.com/LeRoid-hub/Mensa-API.git
synced 2025-01-31 03:34:57 +00:00
Merge pull request #9 from LeRoid-hub/8-custom-cache-lifetime
cusom Cache lifetime
This commit is contained in:
commit
5e9a6b12d9
@ -23,10 +23,11 @@ class SiteCache {
|
||||
return this.cachedData;
|
||||
}
|
||||
|
||||
set(key: string, data: any) {
|
||||
set(key: string, data: any, lifeTime: number = 1000 * 60 * 30) {
|
||||
this.cachedData = data;
|
||||
this.lastUsed = new Date();
|
||||
this.key = key;
|
||||
this.lifeTime = lifeTime;
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,10 +47,10 @@ export default class Cache {
|
||||
return null;
|
||||
}
|
||||
|
||||
set(key: string, data: any) {
|
||||
set(key: string, data: any, lifeTime: number = 1000 * 60 * 30) {
|
||||
for (let i = 0; i < this.cache.length; i++) {
|
||||
if (this.cache[i].key === key) {
|
||||
this.cache[i].set(key, data);
|
||||
this.cache[i].set(key, data, lifeTime);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,8 @@ app.get("/api/bl/:Bundesland", (req: Request, res: Response) => {
|
||||
return res.send("Invalid request");
|
||||
}
|
||||
stripedData = stripCampus(data);
|
||||
cache.set("BL: "+req.params.Bundesland, stripedData);
|
||||
const lifeTime = 1000 * 60 * 60 * 24 * 7;
|
||||
cache.set("BL: "+req.params.Bundesland, stripedData, lifeTime);
|
||||
res.send(stripedData);
|
||||
});
|
||||
}
|
||||
@ -59,13 +60,16 @@ app.get("/api/:Location/:Mensa?", (req: Request, res: Response) => {
|
||||
}
|
||||
fetch(url).then((data) => {
|
||||
let stripedData = null;
|
||||
let lifeTime = 1000 * 30;
|
||||
if (data === null) {
|
||||
return res.send("Invalid request");
|
||||
}
|
||||
if (req.params.Mensa !== undefined) {
|
||||
stripedData = stripMensa(data);
|
||||
lifeTime = 1000 * 60 * 60 * 24;
|
||||
}else {
|
||||
stripedData = stripCampus(data);
|
||||
lifeTime = 1000 * 60 * 30;
|
||||
}
|
||||
|
||||
cache.set(req.params.Mensa ?? req.params.Location, stripedData);
|
||||
|
Loading…
Reference in New Issue
Block a user