diff --git a/gvdb/gvdb-builder.c b/gvdb/gvdb-builder.c
index 91adec6..f437cee 100644
--- a/gvdb/gvdb-builder.c
+++ b/gvdb/gvdb-builder.c
@@ -23,12 +23,16 @@
 #include "gvdb-format.h"
 
 #include <glib.h>
+#include <glib/gstdio.h>
 #include <fcntl.h>
 #if !defined(G_OS_WIN32) || !defined(_MSC_VER)
 #include <unistd.h>
+#include <sys/vfs.h>
 #endif
 #include <string.h>
 
+#define MIN_SLEEP_TIME 100000
+#define MAX_SLEEP_TIME 300000
 
 struct _GvdbItem
 {
@@ -504,12 +508,48 @@ gvdb_table_write_contents (GHashTable   *table,
   gboolean status;
   FileBuilder *fb;
   GString *str;
+  gchar   *lock_filename;
+  int      lock_fd;
+  gboolean on_nfs = TRUE;
+#if !defined(G_OS_WIN32) || !defined(_MSC_VER)
+  struct statfs buf;
+#endif
 
   fb = file_builder_new (byteswap);
   file_builder_add_hash (fb, table, &root);
   str = file_builder_serialise (fb, root);
 
+#if !defined(G_OS_WIN32) || !defined(_MSC_VER)
+  /* Check whether the file 'filename' is on NFS share */
+  if (statfs (filename, &buf) == 0 &&
+      buf.f_type != 0x6969)
+    on_nfs = FALSE;
+#endif
+
+  if (on_nfs)
+    {
+      lock_filename = g_strdup_printf ("%s-lock", filename);
+
+      /* Create a lock file for the file 'filename' */
+      while (link (filename, lock_filename) == -1)
+        {
+          /* Wait some time before another try */
+          g_usleep (g_random_int_range (MIN_SLEEP_TIME, MAX_SLEEP_TIME + 1));
+
+          /* Refresh cache of NFS client for file 'lock_filename' */
+          if ((lock_fd = g_open (lock_filename, O_SYNC)) != -1)
+            close (lock_fd);
+        }
+    }
+
   status = g_file_set_contents (filename, str->str, str->len, error);
+
+  if (on_nfs)
+    {
+      g_unlink (lock_filename);
+      g_free (lock_filename);
+    }
+
   g_string_free (str, TRUE);
 
   return status;
