py_alpaca_api.cache
Cache module for py-alpaca-api.
This module provides caching functionality to improve performance and reduce API calls.
Submodules
Classes
Configuration for cache system. |
|
Types of cache backends supported. |
|
Manages caching for py-alpaca-api. |
Package Contents
- class py_alpaca_api.cache.CacheConfig[source]
Configuration for cache system.
- cache_type
Type of cache backend to use
- max_size
Maximum number of items in memory cache
- default_ttl
Default time-to-live in seconds
- data_ttls
TTL overrides per data type
- redis_host
Redis host (if using Redis)
- redis_port
Redis port (if using Redis)
- redis_db
Redis database number (if using Redis)
- redis_password
Redis password (if using Redis)
- enabled
Whether caching is enabled
- class py_alpaca_api.cache.CacheType(*args, **kwds)[source]
Bases:
enum.EnumTypes of cache backends supported.
- MEMORY = 'memory'
- REDIS = 'redis'
- DISABLED = 'disabled'
- class py_alpaca_api.cache.CacheManager(config: py_alpaca_api.cache.cache_config.CacheConfig | None = None)[source]
Manages caching for py-alpaca-api.
- generate_key(prefix: str, **kwargs) str[source]
Generate cache key from prefix and parameters.
- Parameters:
prefix – Key prefix (e.g., “bars”, “quotes”)
**kwargs – Parameters to include in key
- Returns:
Cache key
- get(key: str, data_type: str | None = None) Any | None[source]
Get item from cache.
- Parameters:
key – Cache key
data_type – Optional data type for metrics
- Returns:
Cached value or None if not found
- set(key: str, value: Any, data_type: str, ttl: int | None = None) None[source]
Set item in cache.
- Parameters:
key – Cache key
value – Value to cache
data_type – Type of data (for TTL lookup)
ttl – Optional TTL override in seconds
- delete(key: str) bool[source]
Delete item from cache.
- Parameters:
key – Cache key
- Returns:
True if deleted, False if not found
- clear(prefix: str | None = None) int[source]
Clear cache items.
- Parameters:
prefix – Optional prefix to clear only specific items
- Returns:
Number of items cleared