proxywhirl.cache.models¶
Pydantic models for cache data structures.
Defines data models for cache entries, configurations, and statistics used across the three-tier caching system (L1/L2/L3).
Classes¶
Configuration for cache behavior and tier settings. |
|
Container for a single cached proxy with metadata. |
|
Aggregate cache statistics across all tiers. |
|
Configuration for a single cache tier. |
|
Type of cache tier. |
|
L2 cache backend type. |
|
Statistics for a single cache tier. |
Module Contents¶
- class proxywhirl.cache.models.CacheConfig(/, **data)[source]¶
Bases:
pydantic.BaseModelConfiguration for cache behavior and tier settings.
Aggregates configuration for all three tiers plus global settings like TTL, cleanup intervals, and storage paths.
Example
>>> config = CacheConfig( ... default_ttl_seconds=3600, ... l1_config=CacheTierConfig(max_entries=1000), ... )
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.cache.models.CacheEntry(/, **data)[source]¶
Bases:
pydantic.BaseModelContainer for a single cached proxy with metadata.
Stores proxy information with TTL, health status, and access tracking. Credentials are SecretStr in memory, encrypted at rest in L2/L3.
Example
>>> entry = CacheEntry( ... key="abc123", ... proxy_url="http://proxy.com:8080", ... source="fetched", ... fetch_time=datetime.now(timezone.utc), ... ttl_seconds=3600, ... ) >>> entry.is_expired False
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.cache.models.CacheStatistics(/, **data)[source]¶
Bases:
pydantic.BaseModelAggregate cache statistics across all tiers.
Combines tier-level statistics and tracks cross-tier operations like promotions and demotions.
Example
>>> stats = CacheStatistics() >>> stats.l1_stats.hits = 100 >>> stats.overall_hit_rate 1.0
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.cache.models.CacheTierConfig(/, **data)[source]¶
Bases:
pydantic.BaseModelConfiguration for a single cache tier.
Defines capacity, eviction policy, and enable/disable state for one tier (L1, L2, or L3).
Example
>>> config = CacheTierConfig(max_entries=1000, eviction_policy="lru")Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.cache.models.CacheTierType[source]¶
-
Type of cache tier.
Initialize self. See help(type(self)) for accurate signature.
- class proxywhirl.cache.models.L2BackendType[source]¶
-
L2 cache backend type.
Determines which storage backend is used for the L2 disk cache tier.
JSONL: File-based using JSON Lines format. Human-readable, portable, best for <10K entries. Uses sharded files with file locking.
SQLITE: Database-based using SQLite. Faster for >10K entries with O(log n) indexed lookups. Better concurrency and atomic operations.
Initialize self. See help(type(self)) for accurate signature.
- class proxywhirl.cache.models.TierStatistics(/, **data)[source]¶
Bases:
pydantic.BaseModelStatistics for a single cache tier.
Tracks hits, misses, evictions by reason, and computes hit rate.
Example
>>> stats = TierStatistics(hits=100, misses=20) >>> stats.hit_rate 0.8333...
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)