# LangCacheSemanticCache

> **Class** in `langchain_redis`

📖 [View in docs](https://reference.langchain.com/python/langchain-redis/cache/LangCacheSemanticCache)

Managed LangCache-backed semantic cache.

This uses `redisvl.extensions.cache.llm.LangCacheSemanticCache` (a wrapper over the
managed LangCache API). The optional dependency `langcache` must be installed at
runtime when this class is used.

Install with either `pip install 'langchain-redis[langcache]'` or
`pip install langcache`.

## Signature

```python
LangCacheSemanticCache(
    self,
    distance_threshold: float = 0.2,
    ttl: Optional[int] = None,
    name: Optional[str] = _DEFAULT_CACHE_NAME,
    *,
    server_url: Optional[str] = None,
    api_key: Optional[str] = None,
    cache_id: Optional[str] = None,
    use_exact_search: bool = True,
    use_semantic_search: bool = True,
    distance_scale: Literal['normalized', 'redis'] = 'normalized',
    **kwargs: Any = {},
)
```

## Description

**Example:**

```python
from langchain_redis import LangCacheSemanticCache

cache = LangCacheSemanticCache(
    cache_id="your-cache-id",
    api_key="your-api-key",
    name="mycache",
    ttl=3600,
)
```

**Notes:**

- Embeddings are computed server-side in LangCache; client-side embeddings
    are not used.
- Per-entry TTL is ignored; cache-level TTL applies if set.

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `distance_threshold` | `float` | No | Maximum distance for semantic matches. (default: `0.2`) |
| `ttl` | `Optional[int]` | No | Cache TTL in seconds.  If `None`, entries do not expire. (default: `None`) |
| `name` | `Optional[str]` | No | Cache name used by LangCache.  Defaults to `'llmcache'`. (default: `_DEFAULT_CACHE_NAME`) |
| `server_url` | `Optional[str]` | No | LangCache API endpoint.  If not set, a default managed endpoint is used; prefer the server URL provided for your cache. (default: `None`) |
| `api_key` | `Optional[str]` | No | API key for LangCache authentication. (default: `None`) |
| `cache_id` | `Optional[str]` | No | Required LangCache instance identifier. (default: `None`) |
| `use_exact_search` | `bool` | No | Enable exact match search. (default: `True`) |
| `use_semantic_search` | `bool` | No | Enable semantic search. (default: `True`) |
| `distance_scale` | `Literal['normalized', 'redis']` | No | Distance scaling mode. (default: `'normalized'`) |
| `**kwargs` | `Any` | No | Additional options forwarded to the LangCache wrapper. (default: `{}`) |

## Extends

- `BaseCache`

## Constructors

```python
__init__(
    self,
    distance_threshold: float = 0.2,
    ttl: Optional[int] = None,
    name: Optional[str] = _DEFAULT_CACHE_NAME,
    *,
    server_url: Optional[str] = None,
    api_key: Optional[str] = None,
    cache_id: Optional[str] = None,
    use_exact_search: bool = True,
    use_semantic_search: bool = True,
    distance_scale: Literal['normalized', 'redis'] = 'normalized',
    **kwargs: Any = {},
)
```

| Name | Type |
|------|------|
| `distance_threshold` | `float` |
| `ttl` | `Optional[int]` |
| `name` | `Optional[str]` |
| `server_url` | `Optional[str]` |
| `api_key` | `Optional[str]` |
| `cache_id` | `Optional[str]` |
| `use_exact_search` | `bool` |
| `use_semantic_search` | `bool` |
| `distance_scale` | `Literal['normalized', 'redis']` |


## Properties

- `cache`
- `ttl`

## Methods

- [`lookup()`](https://reference.langchain.com/python/langchain-redis/cache/LangCacheSemanticCache/lookup)
- [`update()`](https://reference.langchain.com/python/langchain-redis/cache/LangCacheSemanticCache/update)
- [`clear()`](https://reference.langchain.com/python/langchain-redis/cache/LangCacheSemanticCache/clear)
- [`name()`](https://reference.langchain.com/python/langchain-redis/cache/LangCacheSemanticCache/name)
- [`alookup()`](https://reference.langchain.com/python/langchain-redis/cache/LangCacheSemanticCache/alookup)
- [`aupdate()`](https://reference.langchain.com/python/langchain-redis/cache/LangCacheSemanticCache/aupdate)
- [`aclear()`](https://reference.langchain.com/python/langchain-redis/cache/LangCacheSemanticCache/aclear)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-redis/blob/17794ab183d4abde98747360f251478088836347/libs/redis/langchain_redis/cache.py#L728)