Cache
π€ AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
provide.foundation.serialization.cache
¶
Functions¶
get_cache_enabled
¶
get_cache_key
¶
Generate cache key from content and format.
Uses a (format, hash) tuple as the key to avoid intermediate string allocations. Python's built-in hash() is a single C-level operation that returns an int β no encode(), no hexdigest(), no slicing.
Note: hash() is not stable across Python processes (PYTHONHASHSEED), but that's fine for an in-process LRU cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
String content to hash |
required |
format
|
str
|
Format identifier (json, yaml, toml, etc.) |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, int]
|
Cache key tuple |
Source code in provide/foundation/serialization/cache.py
get_cache_size
¶
get_serialization_cache
¶
Get or create serialization cache with thread-safe lazy initialization.
Lock overhead (~20-50ns) is negligible compared to actual cache operations (~100-1000ns lookup, ~1-100ΞΌs for serialization).
Source code in provide/foundation/serialization/cache.py
reset_serialization_cache_config
¶
Reset cached config for testing purposes.
Thread-safe reset that acquires the lock.