Skip to content

Commit

Permalink
fix(cache): generate hashed path keys
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 1, 2022
1 parent d5d802f commit 6104c54
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/runtime/cache.ts
Expand Up @@ -109,7 +109,10 @@ export function defineCachedEventHandler <T=any> (
const _opts: CacheOptions<ResponseCacheEntry<T>> = {
...opts,
getKey: (event) => {
return decodeURI(parseURL(event.req.originalUrl || event.req.url).pathname).replace(/\/$/, '/index')
const url = event.req.originalUrl || event.req.url
const friendlyName = decodeURI(parseURL(url).pathname).replace(/[^a-zA-Z0-9]/g, '').substring(0, 16)
const urlHash = hash(url)
return `${friendlyName}.${urlHash}`
},
group: opts.group || 'nitro/handlers',
integrity: [
Expand Down

0 comments on commit 6104c54

Please sign in to comment.