Skip to content

Commit 2d5ad6d

Browse files
committed
Add cache clear endpoint
1 parent a4df047 commit 2d5ad6d

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

libs/classes/AbstractCloudProvider.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ module.exports = class AbstractCloudProvider{
2424

2525
// Providers should override this function to validate a user token
2626
// and optionally provide a list of restrictions on the user
27+
28+
// @param token {String} a token passed to the proxy to authenticate a request
29+
// Clear user specific caches (if any)
30+
clearCache(token){
31+
// Nothing
32+
}
2733

2834
// @param token {String} a token passed to the proxy to authenticate a request
2935
// @return {Object} See LocalCloudProvider for an example.

libs/classes/ValueCache.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ module.exports = class ValueCache{
4646
});
4747
}
4848

49+
clear(key){
50+
if (this.cache[key] !== undefined) delete(this.cache[key]);
51+
}
52+
4953
get(key){
5054
if (this.enabled &&
5155
this.cache[key] !== undefined &&

libs/cloud-providers/LightningCloudProvider.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = class LightningCloudProvider extends AbstractCloudProvider{
2525
constructor(){
2626
super();
2727

28-
this.validateCache = new ValueCache({expires: 15 * 60 * 1000});
28+
this.validateCache = new ValueCache({expires: 60 * 60 * 1000});
2929

3030
this.urlBase = "https://webodm.net/r";
3131
this.timeout = 15000;
@@ -35,6 +35,10 @@ module.exports = class LightningCloudProvider extends AbstractCloudProvider{
3535
return `${this.urlBase}${url}`
3636
}
3737

38+
clearCache(token){
39+
this.validateCache.clear(token);
40+
}
41+
3842
async validate(token){
3943
if (!token) return {valid: false};
4044
const cached = this.validateCache.get(token);

libs/proxy.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,14 @@ module.exports = {
159159
const options = await getLimitedOptions(token, limits, node);
160160
json(res, options);
161161
}
162-
}
162+
},
163+
164+
'/cache/clear': async function(req, res, user){
165+
const { token } = user;
166+
optionsCache.clear(token);
167+
cloudProvider.clearCache(token);
168+
json(res, {ok: true});
169+
},
163170
}
164171

165172
// Listen for the `error` event on `proxy`.

0 commit comments

Comments
 (0)