DiskProtocol
DiskProtocol
Bases: Protocol
Cache key and value serialization for SQLite database and files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | PathLike[str]
|
directory for cache |
required |
|
Any
|
additional keyword arguments. These arguments may not be used directly in this class, but are added to prevent errors in inherited classes. |
{}
|
Source code in src/typed_diskcache/interface/disk.py
hash
put
Convert key to a format suitable for storage in the Cache table.
This method takes a key and converts it into a database-compatible key and a boolean indicating whether the key is in its raw form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The key to convert. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Any, bool]
|
(database key, raw boolean) pair |
Source code in src/typed_diskcache/interface/disk.py
get
Convert fields key and raw from Cache table to a Python key.
This method takes a database key and a flag indicating if the key is stored in its raw form, and converts them back to the corresponding Python key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The database key to convert. |
required |
|
bool
|
A flag indicating if the key is stored in its raw form. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The corresponding Python key. |
Source code in src/typed_diskcache/interface/disk.py
prepare
Prepare filename and full-path tuple for file storage.
This method takes a value and an optional key, and prepares a full path for storing the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The value to store. |
required |
|
Any
|
The key for the item (optional). |
...
|
Returns:
| Type | Description |
|---|---|
Path | None
|
A full path, or None if preparation fails. |
Source code in src/typed_diskcache/interface/disk.py
store
store(
value: Any,
*,
key: Any = ...,
filepath: Path | None = ...
) -> tuple[int, CacheMode, str | None, bytes | None]
Convert value to fields for Cache table.
This method converts a value into a tuple containing the size, mode, filename, and value suitable for storage in the Cache table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The value to store. |
required |
|
Any
|
The key for the item. |
...
|
|
Path | None
|
The full path for the file. |
...
|
Returns:
| Type | Description |
|---|---|
tuple[int, CacheMode, str | None, bytes | None]
|
(size, mode, filename, value) tuple for Cache table |
Source code in src/typed_diskcache/interface/disk.py
astore
async
astore(
value: Any,
*,
key: Any = ...,
filepath: Path | None = ...
) -> tuple[int, CacheMode, str | None, bytes | None]
Asynchronously convert value to fields for Cache table.
This method is the asynchronous version of
store.
It converts a value into a tuple containing the size, mode, filename, and value
suitable for storage in the Cache table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The value to store. |
required |
|
Any
|
The key for the item. |
...
|
|
Path | None
|
The full path for the file. |
...
|
Returns:
| Type | Description |
|---|---|
tuple[int, CacheMode, str | None, bytes | None]
|
(size, mode, filename, value) tuple for Cache table |
Source code in src/typed_diskcache/interface/disk.py
fetch
Convert fields from Cache table to a Python value.
This method converts the fields mode, filename, and value from the Cache
table back to the corresponding Python value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CacheMode
|
The mode of the value (none, binary, text, or pickle). |
required |
|
str | PathLike[str] | None
|
The filename of the corresponding value. |
required |
|
Any
|
The database value. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The corresponding Python value. |
Source code in src/typed_diskcache/interface/disk.py
afetch
async
Asynchronously convert fields from Cache table to a Python value.
This method is the asynchronous version of
fetch.
It converts the fields mode, filename, and value
from the Cache table back to the corresponding Python value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CacheMode
|
The mode of the value (none, binary, text, or pickle). |
required |
|
str | PathLike[str] | None
|
The filename of the corresponding value. |
required |
|
Any
|
The database value. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The corresponding Python value. |
Source code in src/typed_diskcache/interface/disk.py
remove
aremove
async
Asynchronously remove a file given by file_path.
This method is the asynchronous version of
remove.
It is cross-thread and cross-process safe.
If an OSError occurs, it is suppressed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | PathLike[str]
|
The relative path to the file. |
required |
Source code in src/typed_diskcache/interface/disk.py
filename
Return full-path for file storage.
Filename will be a randomly generated 28 character hexadecimal string with ".val" suffixed. Two levels of sub-directories will be used to reduce the size of directories. On older filesystems, lookups in directories with many files may be slow.
The default implementation ignores the key and value parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
key for item. |
...
|
|
Any
|
value for item. |
...
|
Returns:
| Type | Description |
|---|---|
Path
|
full-path |