(key: string)
| 68 | } |
| 69 | |
| 70 | const get = (key: string) => { |
| 71 | sweep() |
| 72 | const entry = store.get(key) |
| 73 | if (entry && !expired(entry)) { |
| 74 | touch(key, entry) |
| 75 | return entry.value |
| 76 | } |
| 77 | if (entry) { |
| 78 | store.delete(key) |
| 79 | dispose(key, entry) |
| 80 | } |
| 81 | |
| 82 | const created = { |
| 83 | value: createValue(key), |
| 84 | touchedAt: now(), |
| 85 | } |
| 86 | store.set(key, created) |
| 87 | prune() |
| 88 | return created.value |
| 89 | } |
| 90 | |
| 91 | const clear = () => { |
| 92 | for (const [key, entry] of store) { |