* @param {string} name * @param {number|undefined} opt_duration * @return {*|undefined}
(name, opt_duration)
| 215 | * @return {*|undefined} |
| 216 | */ |
| 217 | get(name, opt_duration) { |
| 218 | // The structure is {key: {v: *, t: time}} |
| 219 | const item = this.values_[name]; |
| 220 | const timestamp = item ? item['t'] : undefined; |
| 221 | const isNotExpired = |
| 222 | opt_duration && timestamp != undefined |
| 223 | ? timestamp + opt_duration > Date.now() |
| 224 | : true; |
| 225 | const value = item && isNotExpired ? item['v'] : undefined; |
| 226 | return value; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Set the storage value along with the current timestamp. |