Decorators¶
Caching decorators for Arshai agents and workflows.
Functions¶
- arshai.cache.decorators.cache_result(ttl=300, key_prefix='', key_func=None, cache_none=False)[source]¶
Decorator to cache agent/workflow results.
This decorator provides transparent caching for expensive operations. It works with any object that has a ‘memory’ attribute implementing get/set methods.
Example
- class MyAgent(BaseAgent):
@cache_result(ttl=600, key_prefix=”analysis”) async def analyze_data(self, input_data):
# Expensive operation return result
@cache_result(ttl=3600) def process_sync(self, data):
# Sync method also supported return processed_data
- arshai.cache.decorators.create_key_func(include_args=True, include_kwargs=True, hash_objects=True)[source]¶
Create a custom key generation function.
- Parameters:
- Returns:
Key generation function
Example
@cache_result(key_func=create_key_func(include_kwargs=False)) def my_func(self, x, y=10):
# Only x will be used for cache key, y will be ignored return x * y