Matt Williams avatar Matt Williams committed 81f927e

Cache the mapping to a pickled file.

Comments (0)

Files changed (1)


 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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.