@@ -135,17 +135,18 @@ END
135135 @io << " \n "
136136 @io << ident ident " if (cacheConfig.#{ op.pretty_name } ) {\n "
137137 @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 "
141141 @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 "
142143 @io << ident ident ident ident " if (cache && (!cache.expirationDate || cache.expirationDate > new Date())) return cache.ret;\n "
143144 @io << ident ident ident " } catch(e) {console.log(JSON.stringify(e));}\n "
144145 @io << ident ident " }\n "
145146 @io << ident ident " const ret = await fn.#{ op.pretty_name } (#{ ([" ctx" ] + op.args.map(& .name)).join(" , " ) } );\n "
146147 @io << ident ident op.return_type.typescript_check_decoded(" ret" , " \" #{ op.pretty_name } .ret\" " )
147148 @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 "
149150 @io << ident ident " return encodedRet"
150151 @io << ident " },\n "
151152 end
0 commit comments