filesystem

Summary

FileBackend([cache_name, use_temp, autoclose])

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, autoclose=True, **kwargs)

Bases: CacheBackend

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

Notes

  • Requires aiofiles and aiosqlite.

  • 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 (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.

  • autoclose (bool) – Close any active backend connections when the session is closed

  • kwargs (Any) – Additional keyword arguments for CacheBackend

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

Bases: BaseCache

A dictionary-like interface to files on the local filesystem

Parameters:
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

Parameters:

key (str)

Return type:

bool

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.

Parameters:

key (str)

Return type:

Union[CachedResponse, bytes, str, None]

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: