def write_cache(cache_file, cache_data):
	try:
		path = os.path.dirname(cache_file)
		if not os.path.isdir(path):
			os.mkdir(path)
		cPickle.dump(cache_data, open(cache_file, 'w'), -1)
	except Exception, ex:
		print "Failed to write cache data to %s:" % cache_file, ex