From 1c936429513c37f9d4f502c5c553fb4b1ae7fb54 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 30 Dec 2023 19:43:26 +0530 Subject: [PATCH] (docs) caching use context manager --- docs/my-website/docs/caching/redis_cache.md | 33 ++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/docs/my-website/docs/caching/redis_cache.md b/docs/my-website/docs/caching/redis_cache.md index e480cd39a..cbe8c5b10 100644 --- a/docs/my-website/docs/caching/redis_cache.md +++ b/docs/my-website/docs/caching/redis_cache.md @@ -28,8 +28,39 @@ response2 = completion( # response1 == response2, response 1 is cached ``` -### Custom Cache Keys: +## Cache Context Manager - Enable, Disable, Update Cache +Use the context manager for easily enabling, disabling & updating the litellm cache +### Enabling Cache + +Quick Start Enable +```python +litellm.enable_cache() +``` + +Advanced Params + +```python +litellm.enable_cache( + type: Optional[Literal["local", "redis"]] = "local", + host: Optional[str] = None, + port: Optional[str] = None, + password: Optional[str] = None, + supported_call_types: Optional[ + List[Literal["completion", "acompletion", "embedding", "aembedding"]] + ] = ["completion", "acompletion", "embedding", "aembedding"], + **kwargs, +) +``` + +### Disabling Cache + +Switch caching off +```python +litellm.disable_cache() +``` + +## Custom Cache Keys: Define function to return cache key ```python # this function takes in *args, **kwargs and returns the key you want to use for caching