Skip to content

Models

Settings pydantic-model

Bases: BaseModel

Settings for the cache.

Show JSON schema:
{
  "$defs": {
    "EvictionPolicy": {
      "description": "DiskCache eviction policies.",
      "enum": [
        "none",
        "least-recently-stored",
        "least-recently-used",
        "least-frequently-used"
      ],
      "title": "EvictionPolicy",
      "type": "string"
    },
    "JsonValue": {},
    "SQLiteSettings": {
      "properties": {
        "sqlite_auto_vacuum": {
          "default": "FULL",
          "enum": [
            0,
            "NONE",
            1,
            "FULL",
            2,
            "INCREMENTAL"
          ],
          "title": "Sqlite Auto Vacuum"
        },
        "sqlite_cache_size": {
          "default": 8192,
          "title": "Sqlite Cache Size",
          "type": "integer"
        },
        "sqlite_journal_mode": {
          "default": "WAL",
          "enum": [
            "DELETE",
            "TRUNCATE",
            "PERSIST",
            "MEMORY",
            "WAL",
            "OFF"
          ],
          "title": "Sqlite Journal Mode",
          "type": "string"
        },
        "sqlite_mmap_size": {
          "default": 67108864,
          "title": "Sqlite Mmap Size",
          "type": "integer"
        },
        "sqlite_synchronous": {
          "default": "NORMAL",
          "enum": [
            0,
            "OFF",
            1,
            "NORMAL",
            2,
            "FULL",
            3,
            "EXTRA"
          ],
          "title": "Sqlite Synchronous"
        }
      },
      "title": "SQLiteSettings",
      "type": "object"
    }
  },
  "description": "Settings for the cache.",
  "properties": {
    "statistics": {
      "default": false,
      "title": "Statistics",
      "type": "boolean"
    },
    "eviction_policy": {
      "$ref": "#/$defs/EvictionPolicy",
      "default": "least-recently-stored"
    },
    "size_limit": {
      "default": 1073741824,
      "title": "Size Limit",
      "type": "integer"
    },
    "cull_limit": {
      "default": 10,
      "title": "Cull Limit",
      "type": "integer"
    },
    "serialized_disk": {
      "anyOf": [
        {
          "maxItems": 2,
          "minItems": 2,
          "prefixItems": [
            {
              "type": "string"
            },
            {
              "additionalProperties": {
                "$ref": "#/$defs/JsonValue"
              },
              "type": "object"
            }
          ],
          "type": "array"
        },
        {
          "contentMediaType": "application/json",
          "contentSchema": {
            "maxItems": 2,
            "minItems": 2,
            "prefixItems": [
              {
                "type": "string"
              },
              {
                "additionalProperties": {
                  "$ref": "#/$defs/JsonValue"
                },
                "type": "object"
              }
            ],
            "type": "array"
          },
          "type": "string"
        }
      ],
      "title": "Serialized Disk"
    },
    "sqlite_settings": {
      "$ref": "#/$defs/SQLiteSettings"
    }
  },
  "title": "Settings",
  "type": "object"
}

Config:

  • frozen: True
  • use_enum_values: True

Fields:

load_disk staticmethod

load_disk(
    cls_path: str | None = None,
) -> type[DiskProtocol]

Load disk class.

Source code in src/typed_diskcache/model.py
@staticmethod
def load_disk(cls_path: str | None = None) -> type[DiskProtocol]:
    """Load disk class."""
    if cls_path is None:
        cls_path = "typed_diskcache.Disk"
    module_path, cls_name = cls_path.rsplit(".", 1)
    module = import_module(module_path)
    return getattr(module, cls_name)

create_disk

create_disk(directory: str | PathLike[str]) -> DiskProtocol

Create disk instance.

Source code in src/typed_diskcache/model.py
def create_disk(self, directory: str | PathLike[str]) -> DiskProtocol:
    """Create disk instance."""
    cls_path, kwargs = self.serialized_disk

    kwargs.pop("directory", None)
    disk_type = self.load_disk(cls_path)
    return disk_type(directory, **kwargs)