You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current docs state that SimpleCache.getOrSet() returns a SimpleCacheEntry, which is not accurate.
In fact, it returns Promise that resolves to SimpleCacheEntry
Then, example should look like this, with proper await calls
import{SimpleCache}from'fastly:cache';addEventListener('fetch',event=>event.respondWith(app(event)));asyncfunctionapp(event){constpath=newURL(event.request.url).pathname;letpage=awaitSimpleCache.getOrSet(path,async()=>{return{value: awaitrender(path),// Store the page in the cache for 1 minute.ttl: 60}});if(null===page){returnnewResponse(null,{status: 404});}else{letcontent=awaitpage.text();returnnewResponse(content,{headers: {'content-type': 'text/plain;charset=UTF-8'}});}}asyncfunctionrender(path){// expensive/slow function which constructs and returns the contents for a given pathawaitnewPromise(resolve=>setTimeout(resolve,10_000));returnpath;}
The text was updated successfully, but these errors were encountered:
Improve
SimpleCache
API examples forgetOrSet
Current docs state that
SimpleCache.getOrSet() returns a SimpleCacheEntry
, which is not accurate.In fact, it returns
Promise
that resolves toSimpleCacheEntry
Then, example should look like this, with proper
await
callsThe text was updated successfully, but these errors were encountered: