# [✓]  Refresh or clear cached CloudObjects[]?

Posted 1 year ago
1481 Views
|
4 Replies
|
7 Total Likes
|
 cross posted on mathematica.stackexchange.comLet's create an API which creates one file each time it is called/accessed: obj = CloudDeploy[ APIFunction[{} , Put[$RequesterWolframID , "testFiles/" <> DateString["ISODateTime"] <> ".txt" ] & ] , "apiTest" , Permissions -> "Public" ]; CloudEvaluate@CreateDirectory@"testFiles/"; and let's call it: URLRead[obj] CloudObjects["testFiles/"] URLRead[obj] CloudObjects["testFiles/"] But this is not true, if you visit a browser interface they will be there:In fact, once you visit it, CloudObjects cache changes, but only once: URLRead[obj] CloudObjects["testFiles/"] URLRead[obj] CloudObjects["testFiles/"] So how to make sure CloudObjects returns up to date result?I am fine with an additional step to flush the cache, I just want it to be possible programmatically. Answer 4 Replies Sort By: Posted 1 year ago  When you use Put with a string as the location it just creates a regular file, not a CloudObject. What's happening is that viewing files with the cloud file manager is automatically generating the CloudObject metadata for those files. You'll want to change your code to either Put to a CloudObject explicitly, or preferably just use CloudPut: obj = CloudDeploy[ APIFunction[{} , CloudPut[$RequesterWolframID , "testFiles/" <> DateString["ISODateTime"] <> ".txt" ] & ] , "apiTest" , Permissions -> "Public" ]; Also, there's no need to create the target directory when going directly to cloud objects, since it will be created automatically (as a CloudObject) if necessary.
Posted 1 year ago
 Thanks for your answer, it is a good solution for this case. Can I ask you one further question?The real use case is based on OpenAppend and after having problems with auto creating file or directory I just do If[Not @ FileExistsQ @ #, CreateFile @ #]& @ logFile I only need CloudObjects to know the file is there, metadata can be out of date. What would be the fastest way to CreateFile which is found by CloudObjects? CloudPut["init", logFile]?