Matt Williams  committed 81f927e

Cache the mapping to a pickled file.

  • Participants
  • Parent commits e649f00
  • Branches default

Comments (0)

Files changed (1)

File doxylink/sphinxcontrib/doxylink/

 from parsing import normalise
+import pickle
 def find_url(doc, symbol):
 	Return the URL for a given symbol.
 		tag_file = ET.parse(tag_filename)
-		mapping = parse_tag_file(tag_file)
+		pickle_filename = os.path.basename(tag_filename) + '.pkl'
+		try:
+			if os.stat(pickle_filename).st_mtime < os.stat(tag_filename).st_mtime: #We've already tried to open tag_filename so we know it's good.
+'%s is older than %s. Recreating...' % (pickle_filename, os.path.basename(tag_filename)))
+				mapping = parse_tag_file(tag_file)
+				pickle.dump(mapping, open(pickle_filename, 'wb'))
+			else:
+'Loading pickled data for %s' % os.path.basename(tag_filename))
+				mapping = pickle.load(open(pickle_filename, 'rb'))
+		except OSError as error:
+'Pickle file for %s could not be opened: ' % os.path.basename(tag_filename), error)
+'Recreating from tag file...')
+			mapping = parse_tag_file(tag_file)
+			pickle.dump(mapping, open(pickle_filename, 'wb'))
 	except (IOError):
 		tag_file = None
 		app.warn('Could not open tag file %s. Make sure your `doxylink` config variable is set correctly.' % tag_filename)