code: def get_data(url, gallery_dir):
      
  
      # shelve keys need to be str in python 2
      if sys.version_info[0] == 2 and isinstance(url, unicode):
          url = url.encode('utf-8')
  
      cached_file = os.path.join(gallery_dir, 'searchindex')
      search_index = shelve.open(cached_file)
      if url in search_index:
          data = search_index[url]
      else:
          data = _get_data(url)
          search_index[url] = data
      search_index.close()
  
      return data
docs: Persistent dictionary usage to retrieve the search indexes