File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -105,20 +105,22 @@ export default {
105105 if ( typeof key !== 'string' ) {
106106 throw new TypeError ( 'Cache key must be a string' ) ;
107107 }
108- const v = await cacheModule . get ( key , refresh ) ;
108+ let v = await cacheModule . get ( key , refresh ) ;
109109 if ( v ) {
110+ let parsed ;
110111 try {
111- return JSON . parse ( v ) as T ;
112+ parsed = JSON . parse ( v ) ;
112113 } catch {
113- // Reason: backward compatibility for values stored without JSON.stringify
114- return v as T ;
114+ parsed = null ;
115115 }
116+ if ( parsed ) {
117+ v = parsed ;
118+ }
119+
120+ return v as T ;
116121 } else {
117122 const value = await getValueFunc ( ) ;
118- // Reason: always JSON.stringify to preserve types (e.g. numeric strings
119- // like Mastodon IDs would lose precision if stored as bare strings and
120- // later parsed back as numbers by JSON.parse)
121- cacheModule . set ( key , JSON . stringify ( value ) , maxAge ) ;
123+ cacheModule . set ( key , value , maxAge ) ;
122124
123125 return value ;
124126 }
You can’t perform that action at this time.
0 commit comments