@@ -135,17 +135,18 @@ END
135
135
@io << " \n "
136
136
@io << ident ident " if (cacheConfig.#{ op.pretty_name } ) {\n "
137
137
@io << ident ident ident " try {\n "
138
- @io << ident ident ident ident " const {key: cacheKey , expirationSeconds: cacheExpirationSeconds , version: cacheVersion } = await cacheConfig.#{ op.pretty_name } (#{ ([" ctx" ] + op.args.map(& .name)).join(" , " ) } );\n "
139
- @io << ident ident ident ident " if (!key ) throw \"\" ;\n "
140
- @io << ident ident ident ident " const cacheKeyEncoded = crypto.createHash(\" sha256\" ).update(JSON.stringify(cacheKey )+ \" -#{ op.pretty_name } \" ).digest(\" hex\" ).substr(0, 100); decodedKey = JSON.stringify(cacheKey );\n "
138
+ @io << ident ident ident ident " const {key: _cacheKey , expirationSeconds: _cacheExpirationSeconds , version: _cacheVersion } = await cacheConfig.#{ op.pretty_name } (#{ ([" ctx" ] + op.args.map(& .name)).join(" , " ) } );\n "
139
+ @io << ident ident ident ident " if (!_cacheKey ) throw \"\" ;\n "
140
+ @io << ident ident ident ident " const cacheKeyEncoded = crypto.createHash(\" sha256\" ).update(JSON.stringify(_cacheKey )+ \" -#{ op.pretty_name } \" ).digest(\" hex\" ).substr(0, 100);\n "
141
141
@io << ident ident ident ident " const decodedKey = JSON.stringify(_cacheKey);\n "
142
+ @io << ident ident ident ident " const cache = await hook.getCache(cacheKeyEncoded, _cacheVersion);\n "
142
143
@io << ident ident ident ident " if (cache && (!cache.expirationDate || cache.expirationDate > new Date())) return cache.ret;\n "
143
144
@io << ident ident ident " } catch(e) {console.log(JSON.stringify(e));}\n "
144
145
@io << ident ident " }\n "
145
146
@io << ident ident " const ret = await fn.#{ op.pretty_name } (#{ ([" ctx" ] + op.args.map(& .name)).join(" , " ) } );\n "
146
147
@io << ident ident op.return_type.typescript_check_decoded(" ret" , " \" #{ op.pretty_name } .ret\" " )
147
148
@io << ident ident " const encodedRet = " + op.return_type.typescript_encode(" ret" ) + " ;\n "
148
- @io << ident ident " if (cacheKeyEncoded !== null && cacheVersion !== null) hook.setCache(cacheKeyEncoded, cacheExpirationSeconds ? new Date(new Date().getTime() + (cacheExpirationSeconds * 1000)) : null, cacheVersion , decodedKey!, \" #{ op.pretty_name } \" , encodedRet);\n "
149
+ @io << ident ident " if (cacheKeyEncoded !== null && _cacheVersion !== null) hook.setCache(cacheKeyEncoded, _cacheExpirationSeconds ? new Date(new Date().getTime() + (_cacheExpirationSeconds * 1000)) : null, _cacheVersion , decodedKey!, \" #{ op.pretty_name } \" , encodedRet);\n "
149
150
@io << ident ident " return encodedRet"
150
151
@io << ident " },\n "
151
152
end
0 commit comments