howto force refresh NFS cache when checking newly created file?
<p>When a file is created on a Linux NFS shared mount, the client is either Linux o                                          r mac machines. The existence or absence of a file is the key for what to do next, but the checking is not always return the right result:</p>

<p>e.g I am doing this in perl, this still not working well, esp with mac machines</p>

<pre><code>write_key_file();  # write a file that must be checked before proceeding
</code></pre>

<p>The following checks cannot always return true when the file does exist</p>

<p>Issue - this command in perl did not return correct status in NFS system:</p>

<pre><code>if( -e $file){}
</code></pre>

<p>Overheared solution that did not work:</p>

<pre><code> sleep(5);   # wait 5 seconds
 system("ls -ltr"); # force to cache?
 if(-e $file){}
</code></pre>

<p>I do not intend to check every file like this, but there are a few key places where it is important to get the proper file status.</p>

<p>Do we have better ways to force refresh nfs cache on a specific file on a specific directory? Thanks.</p>

<p>I am not sure that this is a XY problem, but there are a few weakest points that can all be solutions. </p>

<blockquote>
  <p>A -- NFS clients setting </p>
</blockquote>

<p>If there is a solution at this stage, it would be great!</p>

<blockquote>
  <p>B -- exit_code or return code of writing function</p>
</blockquote>

<pre><code>$exit_code = write_key_file();
</code></pre>

<p>The problem with it, not all writing are within the scope of the code block. this only solve part of the problem.</p>

<blockquote>
  <p>C -- Disable NFS cache for the specific file or directory for file checking</p>
</blockquote>

<p>I need to make sure is this possible and how? if no and why?</p>

<p>and I am open to all possible solutions, no solution or other possibilities.</p>