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

do_get_cacheability(self, msg: Message) Cacheability#
Parameters:

msg

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 type of the None singleton.

props.cache_type: CacheType#

The type of the None singleton.

Virtual Methods#

class Cache
do_get_cacheability(msg: Message) Cacheability#

The type of the None singleton.

Parameters:

msg

Fields#

class Cache
parent_instance#