code: def generate_and_cache(path=user_path):
      '''
      Generate category ranges and save to userlevel cache file.
  
      :param path: path to userlevel cache file
      :type path: str
      :returns: category ranges dict
      :rtype: dict of RangeGroup
      '''
      data = tools.generate()
      if not path:
          return data
      try:
          directory = os.path.dirname(path)
          if not os.path.exists(directory):
              os.makedirs(directory)
          with open(path, 'wb') as f:
              pickle.dump((data_version, module_version, data), f)
      except (PermissionError, ValueError) as e:
          warnings.warn('Unable to write cache file "%s": %s' % (path, e))
      return datf generate_and_cache(path=user_path):
      '''
      Generate category ranges and save to userlevel cache file.
  
      :param path: path to userlevel cache file
      :type path: str
      :returns: category ranges dict
      :rtype: dict of RangeGroup
      '''
      data = tools.generate()
      if not path:
          return data
      try:
          directory = os.path.dirname(path)
          if not os.path.exists(directory):
              os.makedirs(directory)
          with open(path, 'wb') as f:
              pickle.dump((data_version, module_version, data), f)
      except (PermissionError, ValueError) as e:
          warnings.warn('Unable to write cache file "%s": %s' % (path, e))
      return data
docs: Generate category ranges and save to userlevel cache file.
  
      :param path: path to userlevel cache file
      :type path: str
      :returns: category ranges dict
      :rtype: dict of RangeGroup