3
$\begingroup$

cross posted on community.wolfram.com

Let'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/"]

enter image description here

But this is not true, if you visit a browser interface they will be there:

enter image description here

In fact, once you visit it, CloudObjects cache changes, but only once:

URLRead[obj]
CloudObjects["testFiles/"]
URLRead[obj]
CloudObjects["testFiles/"]

enter image description here

So how to make sure CloudObjects returns up to date result?

$\endgroup$
  • $\begingroup$ My guess is this is a caching thing, either in your web browser or in the cloud. As of last fall the cloud cached overly aggressively (and yet somehow not enough...). I think Community is a better bet than here, given that you might be able to get a cloud-dev on it. $\endgroup$ – b3m2a1 Dec 9 '17 at 22:18
  • $\begingroup$ @b3m2a1 yep, most probably. I will ask there too. I usually start here because it is faster and the feedback is faster. So I can move to posting further issues. $\endgroup$ – Kuba Dec 9 '17 at 23:30
2
$\begingroup$

Summing up community.wolfram.com feedback:

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

  • Richard Hennigan

But yes, a CloudPut of a tiny expression is probably the fastest way to create a cloud object. (You can include the IconRules -> {} option setting, the icon is generated asynchronously so it won't improve your latency if this is done infrequently, but if you really are hammering the system, this will reduce the overall load on the system and may help some.)

  • Joel Klein

As an alternative solution one can use FileNames, slightly different function but often enough:

CloudEvaluate @ FileNames["*", "testFiles/"]

can eat your cloud credits though.

{ "testFiles/2017-12-09T14:23:35.txt"
, "testFiles/2017-12-09T17:50:09.txt"
, "testFiles/2017-12-09T17:50:17.txt"
, "testFiles/2017-12-09T17:52:24.txt"
, "testFiles/2017-12-09T17:52:31.txt"
}
$\endgroup$
  • 1
    $\begingroup$ The only danger with this is that it decreases $CloudCreditsAvailable $\endgroup$ – b3m2a1 Dec 10 '17 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.