Index: trunk/Ohana/src/opihi/dvo/LoadImages.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/LoadImages.c	(revision 27435)
+++ trunk/Ohana/src/opihi/dvo/LoadImages.c	(revision 28958)
@@ -1,3 +1,13 @@
 # include "dvoshell.h"
+
+// XXX: Maybe make this a command line option
+int dvoUseImageCache = 1;
+
+static char *lastFilename = NULL;
+static time_t lastModified = 0;
+static Image *imageCache = NULL;
+static off_t cacheNimage = 0;
+
+static time_t getLastModified(char *filename);
 
 Image *LoadImages (off_t *Nimage) {
@@ -12,4 +22,21 @@
   catdir = GetCATDIR ();
   sprintf (filename, "%s/Images.dat", catdir);
+
+  if (lastFilename) {
+    if (dvoUseImageCache && !strcmp(lastFilename, filename)) {
+      // Make sure the file hasn't changed since we loaded it
+      if (getLastModified(filename) == lastModified) {
+        *Nimage = cacheNimage;
+        return  imageCache;
+      }
+    }
+    free(lastFilename);
+    lastFilename = NULL;
+    free(imageCache);
+    imageCache = NULL;
+    cacheNimage = 0;
+    lastModified = 0;
+  }
+
 
   gfits_db_init (&db);
@@ -38,4 +65,29 @@
 
   image = gfits_table_get_Image (&db.ftable, Nimage, &db.swapped);
+  if (dvoUseImageCache && image) {
+    cacheNimage = *Nimage;
+    imageCache = image;
+    lastFilename = strdup(filename);
+    lastModified = getLastModified(filename);
+  }
+
   return (image);
 }
+
+static time_t getLastModified(char *filename) {
+  struct stat statbuf;
+  if (!stat(filename, &statbuf)) {
+    return statbuf.st_mtime;
+  } else {
+    return 0;
+  }
+}
+
+void FreeImages(Image *images) {
+  if (!dvoUseImageCache && (images != NULL)) {
+    free(images);
+  } else {
+    // defer free until next LoadImages with a different or modified Images.dat
+  }
+}
+
