Create a html cache. Html string will be automatically compressed.

    :param directory: path for the cache directory.
    :param compress_level: 0 ~ 9, 9 is slowest and smallest.
    :param kwargs: other arguments.
    :return: a `diskcache.Cache()`
334427
def create_cache(directory, compress_level=6, value_type_is_binary=False, **kwargs):
    
    cache = diskcache.Cache(
        directory,
        disk=CompressedDisk,
        disk_compress_level=compress_level,
        disk_value_type_is_binary=value_type_is_binary,
        **kwargs
    )
    return cache
959268
def cache_dir(script)
      # prefix object ID with a text constant to make a legal directory name
      # in case object id is negative (Ubuntu, etc.). this method will be called
      # more than once and must return the same directory each time for a given
      # script instantiation.
      path = File.normalize_path(File.join(AgentConfig.cache_dir, 'right_scripts_content', "rs_attach" + script.object_id.to_s))

      # convert to native format for ease of scripting in Windows, etc. the
      # normalized path is normal for Ruby but not necessarily for native FS.
      return RightScale::Platform.filesystem.pretty_path(path, true)
    end
726334
def cache_persist(self):
        
        filename = self.get_cache_location()
        pickle.dump(self.categories, open(filename, 'wb'))
90308
def _cache_directory(self):
        
        if settings.unit_testing_mode or settings.use_test_cache:
            return os.path.join(settings.cache_directory.replace("Fortpy", "Fortpy_Testing"), self.py_tag)
        else:
            return os.path.join(settings.cache_directory, self.py_tag)
631210
def _get_default_cache_dir(self):
        

        return os.path.join(os.path.dirname(__file__), self._DATA_DIR)
78289
def cache(*args, **kwargs):
    
    ## only one argument ?
    if len(args) == 1 and len(kwargs) == 0 and \
           (callable(args[0]) or \
            isinstance(args[0], tuple(SUPPORTED_DECORATOR.keys()))):
        return _cache_w_args(args[0])
    return lambda f: _cache_w_args(f, *args, **kwargs)
515451
def compress_directory(dir)
      File.open archive_path(dir), 'wb' do |oarchive_path|
        Zlib::GzipWriter.wrap oarchive_path do |gz|
          Gem::Package::TarWriter.new gz do |tar|
            Find.find "#{builds_dir}/"+dir do |f|
              relative_path = f.sub "#{builds_dir}/", ""
              mode = File.stat(f).mode
              size = File.stat(f).size
              
              if File.directory? f
                tar.mkdir relative_path, mode
              else
                tar.add_file_simple relative_path, mode, size do |tio|
                  File.open f, 'rb' do |rio|
                    while buffer = rio.read(BLOCKSIZE_TO_READ)
                      tio.write buffer
                    end
                  end
                end
              end
              
            end
          end
        end
      end
      
    end
274018
def _create_if_necessary(directory):
    

    if not os.path.isabs(directory):
        log.debug("Got non-absolute path: %s" % directory)
        directory = os.path.abspath(directory)

    if not os.path.isdir(directory):
        log.info("Creating directory: %s" % directory)
        try:
            os.makedirs(directory, 0x1C0)
        except OSError as ose:
            log.error(ose, exc_info=1)
            return False
        else:
            log.debug("Created directory.")
    return True
296701
def init(directory=None):
    
    if directory is not None and not path.exists(directory):
        makedirs(directory)
    else:
        print('%s already exists, populating with template files' % (directory))
        directory = ''

    if not path.isfile(path.join(directory,'style.css')):
        grab('style.css', directory)
        print('Added sample style')
    if not path.isfile(path.join(directory,'template.jinja')):
        grab('template.jinja', directory)
        print('Added sample template.jinja')
    if not path.isfile(path.join(directory,'content.rst')):
        grab('content.rst', directory)
        print('Added sample content.rst')
1083518
def _cache_id(minion_id, cache_file):
    '''
    
    '''
    path = os.path.dirname(cache_file)
    try:
        if not os.path.isdir(path):
            os.makedirs(path)
    except OSError as exc:
        # Handle race condition where dir is created after os.path.isdir check
        if os.path.isdir(path):
            pass
        else:
            log.error('Failed to create dirs to minion_id file: %s', exc)

    try:
        with salt.utils.files.fopen(cache_file, 'w') as idf:
            idf.write(minion_id)
    except (IOError, OSError) as exc:
        log.error('Could not cache minion ID: %s', exc)
219248
def init_cachedir(base=None):
    '''
    
    '''
    if base is None:
        base = __opts__['cachedir']
    needed_dirs = (base,
                   os.path.join(base, 'requested'),
                   os.path.join(base, 'active'))
    for dir_ in needed_dirs:
        if not os.path.exists(dir_):
            os.makedirs(dir_)
        os.chmod(base, 0o755)

    return base
284357
function Filecache(options) {
  options = options || {};

  this.directory = options.directory || path.join(__dirname, '/.cache');
  this.fresh = +options.fresh || 500000;
}
1238691
def create_cached_item(self, path, content):
        
        if isinstance(content, Image.Image):
            item_path = '%s/%s/%s' % (
                current_app.static_folder,
                self.cache_folder,
                path.strip('/')
            )
            self.make_dirs(item_path)

            content.save(item_path)

            if os.path.isfile(item_path):
                return '%s/%s/%s' % (current_app.static_url_path, self.cache_folder, path.strip('/'))
            else:  # pragma: no cover
                LOGGER.warning('File is not created on path: %s' % item_path)
                return False
        else:
            return False
502532
def load(cls, directory):
    
    read_file = maybe_read_file(cls._path(directory))
    if read_file:
      fingerprint, length = read_file.split(':')
      return Digest(fingerprint, int(length))
    else:
      return None
328541
def mkdir(self, target_folder):
        
        self.printv("Making directory: %s" % target_folder)
        self.k.key = re.sub(r"^/|/$", "", target_folder) + "/"
        self.k.set_contents_from_string('')
        self.k.close()
1038157
def set_cache(config_fpath, cache_dir):
    
    cache_dir = os.path.abspath(cache_dir)
    return write_config_value_to_file(
        CACHE_DIRECTORY_KEY,
        cache_dir,
        config_fpath
    )
1344415
def _save_cache(self, filename, section_number_of_pages, page_references):
        """"""
        cache_path = Path(filename).with_suffix(self.CACHE_EXTENSION)
        with cache_path.open('wb') as file:
            cache = (section_number_of_pages, page_references)
            pickle.dump(cache, file)