Cache

class Cache(**properties: Any)

Superclasses: Object

Implemented Interfaces: SessionFeature

File-based cache for HTTP resources.

Constructors

class Cache
classmethod new(cache_dir: str | None, cache_type: CacheType) Cache

Creates a new Cache.

Parameters:
  • cache_dir – the directory to store the cached data, or None to use the default one. Note that since the cache isn’t safe to access for multiple processes at once, and the default directory isn’t namespaced by process, clients are strongly discouraged from passing None.

  • cache_type – the CacheType of the cache

Methods

class Cache
clear() None

Will remove all entries in the cache plus all the cache files.

This is not thread safe and must be called only from the thread that created the Cache

dump() None

Synchronously writes the cache index out to disk.

Contrast with flush, which writes pending cache entries to disk.

You must call this before exiting if you want your cache data to persist between sessions.

This is not thread safe and must be called only from the thread that created the Cache

flush() None

Forces all pending writes in the cache to be committed to disk.

For doing so it will iterate the MainContext associated with cache’s session as long as needed.

Contrast with dump, which writes out the cache index file.

get_max_size() int

Gets the maximum size of the cache.

load() None

Loads the contents of cache’s index into memory.

This is not thread safe and must be called only from the thread that created the Cache

set_max_size(max_size: int) None

Sets the maximum size of the cache.

Parameters:

max_size – the maximum size of the cache, in bytes

Properties

class Cache
props.cache_dir: str

The directory to store the cache files.

props.cache_type: CacheType

Whether the cache is private or shared.

Virtual Methods

class Cache
do_get_cacheability(msg: Message) Cacheability
Parameters:

msg

Fields

class Cache
parent_instance