File size: 539 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const cache = new Map()

module.exports = class CacheHandler {
  constructor() {
    console.log('initialized custom cache-handler')
  }

  async get(key, ctx) {
    console.log('cache-handler get', key, ctx)

    if (ctx.softTags?.some((tag) => tag.includes('?'))) {
      throw new Error(`invalid soft tag found should only be pathname`)
    }
    return cache.get(key)
  }

  async set(key, data, ctx) {
    console.log('cache-handler set', key, ctx)
    cache.set(key, {
      value: data,
      lastModified: Date.now(),
    })
  }
}