Page 1 of 1

read verses spew

Posted: Wed Dec 02, 2020 5:32 pm
by gerry.odea
I'm currently using this code below to cache data. The ouput is saved with the WRITE statement. My question is, would it be better if I used the spew statement instead of the read statement? Also is there a way to read the date of the file this way if it's older than a week I could write over it.
Thanks,
Gerry

<IF $page lt 2>
<lower $q2><$searchdirectory="/a/"><$storesearch=($searchdirectory+$ret)><read $storesearch>
<fetch "http://1.1.1.1" $ret><$html=$ret>
<timport max=2 row $imports $html></timport>
<IF $EN="">
<fetch PARALLEL $fetchsearch><$html=$ret></fetch>
<lower $q2><$searchdirectory="/a/"><$storesearch=($searchdirectory+$ret)><WRITE SKIPONFAIL $storesearch><fmt "%s" $html></WRITE>
</IF>
<ELSE>
<fetch PARALLEL $fetchsearch><$html=$ret></fetch>
</if>

read verses spew

Posted: Wed Dec 02, 2020 5:51 pm
by mark
You're reprocessing the file you <read> so spew would not be appropriate. If you were sending the file from disk directly out, then you would use <spew>.

Use <stat> to get file mod times etc.

read verses spew

Posted: Wed Dec 02, 2020 6:07 pm
by gerry.odea
Thanks Mark!
I still can't get this to work, it won't save anything to $FDate

<lower $q2><$searchdirectory="/a/"><$storesearch=($searchdirectory+$ret)><stat $storesearch><$FDate=$ret.mtime>

read verses spew

Posted: Wed Dec 02, 2020 6:46 pm
by Kai
Check (print) $ret.err after the <stat>: if it's non-empty, an error occurred trying to stat the file. Also print $storesearch to verify it's the correct path.