filesystem

Summary

FileBackend([cache_name, use_temp])

Backend that stores cached responses as files on the local filesystem.

FileCache(cache_name[, use_temp])

A dictionary-like interface to files on the local filesystem

Module Contents

class FileBackend(cache_name='http_cache', use_temp=False, **kwargs)

Bases: aiohttp_client_cache.backends.base.CacheBackend

Backend that stores cached responses as files on the local filesystem. Response paths will be in the format <cache_name>/responses/<cache_key>. Redirects are stored in a SQLite database, located at <cache_name>/redirects.sqlite.

Parameters
  • cache_name (Union[Path, str]) – Base directory for cache files

  • use_temp (bool) – Store cache files in a temp directory (e.g., /tmp/http_cache/). Note: if cache_name is an absolute path, this option will be ignored.

class FileCache(cache_name, use_temp=False, **kwargs)

Bases: aiohttp_client_cache.backends.base.BaseCache

A dictionary-like interface to files on the local filesystem

Parameters

use_temp (bool) –

_abc_impl = <_abc_data object>
_join(key)
_try_io(ignore_errors=True)

Attempt an I/O operation, and either ignore errors or re-raise them as KeyErrors

Parameters

ignore_errors (bool) –

async bulk_delete(keys)

Delete item(s) from the cache. Does not raise an error if the item is missing.

Parameters

keys (set) –

async clear()

Note: Currently this is a blocking operation

async contains(key)

Check if a key is stored in the cache

Return type

bool

Parameters

key (str) –

async delete(key)

Delete an item from the cache. Does not raise an error if the item is missing.

Parameters

key (str) –

async keys()

Get all keys stored in the cache

Return type

AsyncIterable[str]

async paths()

Get file paths to all cached responses

async read(key)

Read an item from the cache. Returns None if the item is missing.

Return type

Union[CachedResponse, bytes, str, None]

Parameters

key (str) –

async size()

Get the number of items in the cache

Return type

int

async values()

Get all values stored in the cache

Return type

AsyncIterable[Union[CachedResponse, bytes, str, None]]

async write(key, value)

Write an item to the cache

Parameters
_get_cache_dir(cache_dir, use_temp)
Return type

str

Parameters