From 7c19783d32fbf57e11f159189dc2c4cf4eaddf67 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 24 Feb 2024 18:54:46 -0800 Subject: [PATCH] (docs) writing custo add --- docs/my-website/docs/caching/redis_cache.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/my-website/docs/caching/redis_cache.md b/docs/my-website/docs/caching/redis_cache.md index b54ad2d0c..b00a118c1 100644 --- a/docs/my-website/docs/caching/redis_cache.md +++ b/docs/my-website/docs/caching/redis_cache.md @@ -248,6 +248,27 @@ cache.get_cache_key = custom_get_cache_key # set get_cache_key function for your litellm.cache = cache # set litellm.cache to your cache +``` +## How to write custom add/get cache functions +### 1. Init Cache +```python +from litellm.caching import Cache +cache = Cache() +``` + +### 2. Define custom add/get cache functions +```python +def add_cache(self, result, *args, **kwargs): + your logic + +def get_cache(self, *args, **kwargs): + your logic +``` + +### 3. Point cache add/get functions to your add/get functions +```python +cache.add_cache = add_cache +cache.get_cache = get_cache ``` ## Cache Initialization Parameters