diff -ur dvipdfmx-20110311.orig/data/dvipdfmx.cfg dvipdfmx-20110311/data/dvipdfmx.cfg
--- dvipdfmx-20110311.orig/data/dvipdfmx.cfg	2010-10-12 09:01:29.000000000 +0900
+++ dvipdfmx-20110311/data/dvipdfmx.cfg	2013-03-20 22:23:20.593487776 +0900
@@ -175,6 +175,11 @@
 
 %d  5
 
+%% Image cache life in hours
+%%  0 means erase all old images and leave new images
+%% -1 means erase all old images and also erase new images
+%I 48
+
 %% Font Map Files
 %%
 %% teTeX 2.x and TeX Live using updmap (pdfTeX format)
diff -ur dvipdfmx-20110311.orig/src/dpxfile.c dvipdfmx-20110311/src/dpxfile.c
--- dvipdfmx-20110311.orig/src/dpxfile.c	2011-03-11 12:10:51.000000000 +0900
+++ dvipdfmx-20110311/src/dpxfile.c	2013-03-20 22:23:20.593487776 +0900
@@ -26,6 +26,8 @@
 #include "config.h"
 #endif
 
+#include <time.h>
+
 #include "system.h"
 #include "error.h"
 #include "mem.h"
@@ -34,6 +36,8 @@
 #include "mfileio.h"
 
 #include "dpxfile.h"
+#include "dpxcrypt.h"
+#define MAX_KEY_LEN 16
 
 #include <kpathsea/lib.h>
 #include <string.h>
@@ -53,6 +57,7 @@
 #endif
 
 static int verbose = 0;
+static int keep_cache = false;
 
 void
 dpx_file_set_verbose (void)
@@ -741,6 +746,23 @@
 }
  
 
+static char *
+dpx_get_tmpdir (void)
+{
+#  define __TMPDIR     "/tmp"
+    char *_tmpd;
+
+#  ifdef  HAVE_GETENV
+    _tmpd = getenv("TMPDIR");
+    if (!_tmpd)
+      _tmpd = __TMPDIR;
+#  else
+    _tmpd = __TMPDIR;
+#  endif /* HAVE_GETENV */
+    return _tmpd;
+}
+
+
 #ifdef  HAVE_MKSTEMP
 #  include <stdlib.h>
 /* extern int mkstemp(const char *); */
@@ -761,18 +783,11 @@
     miktex_create_temp_file_name(tmp); /* FIXME_FIXME */
   }
 #elif defined(HAVE_MKSTEMP)
-#  define __TMPDIR     "/tmp"
 #  define TEMPLATE     "/dvipdfmx.XXXXXX"
   {
     const char *_tmpd;
     int   _fd = -1;
-#  ifdef  HAVE_GETENV
-    _tmpd = getenv("TMPDIR");
-    if (!_tmpd)
-      _tmpd = __TMPDIR;
-#  else
-    _tmpd = __TMPDIR;
-#  endif /* HAVE_GETENV */
+    _tmpd = dpx_get_tmpdir();
     tmp = NEW(strlen(_tmpd) + strlen(TEMPLATE) + 1, char);
     strcpy(tmp, _tmpd);
     strcat(tmp, TEMPLATE);
@@ -800,12 +815,75 @@
   return  tmp;
 }
 
+char *
+dpx_create_fix_temp_file (char *filename)
+{
+#define PREFIX "dvipdfmx."
+  static char *dir = NULL;
+  static char *cwd = NULL;
+  char *ret, *s;
+  int i;
+  MD5_CONTEXT state;
+  unsigned char digest[MAX_KEY_LEN];
+
+  if (!dir) {
+      dir = dpx_get_tmpdir();
+      cwd = xgetcwd();
+  }
+
+  MD5_init(&state);
+  MD5_write(&state, (unsigned char *)cwd,      strlen(cwd));
+  MD5_write(&state, (unsigned char *)filename, strlen(filename));
+  MD5_final(digest, &state);
+
+  ret = NEW(strlen(dir)+1+strlen(PREFIX)+MAX_KEY_LEN*2 + 1, char);
+  sprintf(ret, "%s/%s", dir, PREFIX);
+  s = ret + strlen(ret);
+  for (i=0; i<MAX_KEY_LEN; i++) {
+      sprintf(s, "%02x", digest[i]);
+      s += 2;
+  }
+  /* printf("dpx_create_fix_temp_file: %s\n", ret); */
+  return ret;
+}
+
+int
+dpx_clear_cache_filter (const struct dirent *ent) {
+    int plen = strlen(PREFIX);
+    if (strlen(ent->d_name) != plen + MAX_KEY_LEN * 2) return 0;
+    return strncmp(ent->d_name, PREFIX, plen) == 0;
+}
+
+void
+dpx_delete_old_cache (int life)
+{
+  int i;
+  char *dir = dpx_get_tmpdir();
+  char *pathname = NEW(strlen(dir)+1+strlen(PREFIX)+MAX_KEY_LEN*2 + 1, char);
+  struct dirent **list;
+  time_t limit = time(NULL) - life * 60 * 60;
+
+  if (life >= 0) keep_cache = true;
+  i = scandir(dir, &list, dpx_clear_cache_filter, NULL);
+  while (i-- > 0) {
+      sprintf(pathname, "%s/%s", dir, list[i]->d_name);
+      struct stat sb = xstat(pathname);
+      if (sb.st_mtime < limit) {
+          remove(pathname);
+          /* printf("remove: %s\n", pathname); */
+      }
+      free(list[i]);
+  }
+  free(list);
+  RELEASE(pathname);
+}
+
 void
-dpx_delete_temp_file (char *tmp)
+dpx_delete_temp_file (char *tmp, int force)
 {
   if (!tmp)
     return;
-  remove (tmp);
+  if (force || !keep_cache) remove (tmp);
   RELEASE(tmp);
 
   return;
diff -ur dvipdfmx-20110311.orig/src/dpxfile.h dvipdfmx-20110311/src/dpxfile.h
--- dvipdfmx-20110311.orig/src/dpxfile.h	2011-03-06 12:07:03.000000000 +0900
+++ dvipdfmx-20110311/src/dpxfile.h	2013-03-20 22:23:20.593487776 +0900
@@ -57,6 +57,8 @@
                                    const char *input, const char *output,
                                    unsigned char version);
 extern char *dpx_create_temp_file  (void);
-extern void  dpx_delete_temp_file  (char *tmp); /* tmp freed here */
+extern char *dpx_create_fix_temp_file (char *filename);
+extern void  dpx_delete_old_cache  (int life);
+extern void  dpx_delete_temp_file  (char *tmp, int force); /* tmp freed here */
 
 #endif /* _DPXFILE_H_ */
diff -ur dvipdfmx-20110311.orig/src/dvipdfmx.c dvipdfmx-20110311/src/dvipdfmx.c
--- dvipdfmx-20110311.orig/src/dvipdfmx.c	2011-03-08 11:08:35.000000000 +0900
+++ dvipdfmx-20110311/src/dvipdfmx.c	2013-03-20 22:23:20.593487776 +0900
@@ -86,6 +86,11 @@
  */
 static int pdfdecimaldigits = 2;
 
+/* Image cache life in hours */
+/*  0 means erase all old images and leave new images */
+/* -1 means erase all old images and also erase new images */
+static int image_cache_life = 48;
+
 /* Encryption */
 static int do_encryption    = 0;
 static unsigned key_bits    = 40;
@@ -518,6 +523,11 @@
           POP_ARG();
         }
         break;
+      case 'I':
+        CHECK_ARG(1, "image cache life in hours");
+        image_cache_life = (unsigned) atoi(argv[1]);
+        POP_ARG();
+        break;
       case 'S':
         do_encryption = 1;
         break;
@@ -884,6 +894,7 @@
   kpse_set_program_enabled(kpse_pk_format, true, kpse_src_texmf_cnf);
 #endif
   pdf_font_set_dpi(font_dpi);
+  dpx_delete_old_cache(image_cache_life);
 
   if (!dvi_filename) {
     WARN("No dvi filename specified.");
diff -ur dvipdfmx-20110311.orig/src/pdfximage.c dvipdfmx-20110311/src/pdfximage.c
--- dvipdfmx-20110311.orig/src/pdfximage.c	2011-03-06 12:14:15.000000000 +0900
+++ dvipdfmx-20110311/src/pdfximage.c	2013-03-20 22:31:49.393487717 +0900
@@ -195,7 +195,7 @@
 	 */
 	if (_opts.verbose > 1)
 	  MESG("pdf_image>> deleting temporary file \"%s\"\n", I->filename);
-	dpx_delete_temp_file(I->filename); /* temporary filename freed here */
+	dpx_delete_temp_file(I->filename, false); /* temporary filename freed here */
 	I->filename = NULL;
       }
       pdf_clean_ximage_struct(I);
@@ -869,6 +869,8 @@
   char  *temp;
   FILE  *fp;
   int    error = 0;
+  int    exist = false;
+  struct stat stat_o, stat_t;
 
   if (!distiller_template) {
     WARN("No image converter available for converting file \"%s\" to PDF format.", filename);
@@ -876,7 +878,7 @@
     return  -1;
   }
 
-  temp = dpx_create_temp_file();
+  temp = dpx_create_fix_temp_file(filename);
   if (!temp) {
     WARN("Failed to create temporary file for image conversion: %s", filename);
     return  -1;
@@ -889,18 +891,29 @@
     MESG("pdf_image>> ...");
   }
 
+  fp = MFOPEN(temp, FOPEN_RBIN_MODE);
+  if (fp) {
+    stat_o = xstat(filename);
+    stat_t = xstat(temp);
+    /*printf("\nLast file modification: %s", ctime(&stat_o.st_mtime));
+      printf("Last file modification: %s", ctime(&stat_t.st_mtime));*/
+    if (stat_t.st_mtime > stat_o.st_mtime) exist = true;
+    else MFCLOSE(fp);
+  }
+  if (!exist) {
   error = dpx_file_apply_filter(distiller_template, filename, temp,
                                (unsigned char) pdf_get_version());
   if (error) {
     WARN("Image format conversion for \"%s\" failed...", filename);
-    dpx_delete_temp_file(temp);
+    dpx_delete_temp_file(temp, true);
     return  error;
   }
-
   fp = MFOPEN(temp, FOPEN_RBIN_MODE);
+  }
+
   if (!fp) {
     WARN("Could not open conversion result \"%s\" for image \"%s\". Why?", temp, filename);
-    dpx_delete_temp_file(temp);
+    dpx_delete_temp_file(temp, true);
     return  -1;
   }
   pdf_set_ximage_tempfile(ximage, temp);
