mirror of
https://github.com/dwaxweiler/connector-mobilizon
synced 2025-06-05 21:59:25 +02:00
add 2 min request cache, remove a few unneeded semicolons
This commit is contained in:
24
source/connector-mobilizon/front/session-cache.js
Normal file
24
source/connector-mobilizon/front/session-cache.js
Normal file
@ -0,0 +1,24 @@
|
||||
import hash from './object-hash-wrapper'
|
||||
|
||||
const MAX_AGE_IN_MS = 120000
|
||||
|
||||
export class SessionCache {
|
||||
|
||||
static add(parameters, data) {
|
||||
const key = hash(parameters)
|
||||
const timestamp = Date.now()
|
||||
const value = {
|
||||
data,
|
||||
timestamp,
|
||||
}
|
||||
sessionStorage.setItem(key, JSON.stringify(value))
|
||||
}
|
||||
|
||||
static get(parameters) {
|
||||
const key = hash(parameters)
|
||||
const value = JSON.parse(sessionStorage.getItem(key))
|
||||
if (value.timestamp && value.timestamp > Date.now() - MAX_AGE_IN_MS)
|
||||
return value.data
|
||||
return null
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user