You can build a TTL using alarms. Whenever your object is accessed, you would use- KentonsetAlarm()to set the alarm time toDate.now() + timeout. There is only one alarm per object, so each call tosetAlarm()replaces the previous alarm with the new alarm time. When that time is reached, the alarm handler will be invoked. In youralarmhandler, you would usestorage.deleteAll()to delete your object.
Since it’s possible to build TTL using alarms, we probably won’t be adding a separate TTL feature.
env.MY_DO_NAMESPACE.idFromName(name)? Those require a global lookup on object creation and should be avoided.idFromName with the same never-before-used name? Or are there guards around that?idFromName doesn't return a promise since it can be async.idFromName('new-name') and a worker in EU calls idFromName('new-name') at the same time, they'll both have different ids. When they call fetch(req) will they both get a different DO instance, or will the system ensure they are routed to the same DO? I'm looking at using the DO mechanism so that multiple players of an AI text game who are hitting the same un-generated branch of that game will be able to request it and have a unique DO for that branch ensure the request to generate the AI response only happens once and is returned to both players and caches the response in R2 for future players who go down that particular branch. I'm not sure if the guarantee for 1 DO in the world for a given name extended to this case when 2 clients could be asking for the same new name at the same moment.idFromName calls will meet up somewhere in the ether and one will win so that there will only ever be one DO that matches that "name". This cross coordination occurs before a fetch can be called, so they will be "routed to the same DO". That said, I don't know if anyone on this channel has seen the actual code and sequence diagrams that confirm it achieves this intention, but if it doesn't work this way, it's a bug, not expected.setAlarm()setAlarm()Date.now() + timeoutalarmstorage.deleteAll()env.MY_DO_NAMESPACE.idFromName(name)idFromNameidFromNameidFromNameidFromName('new-name')idFromName('new-name')fetch(req)