|
|
2 ay önce | |
|---|---|---|
| .. | ||
| README.md | 7 ay önce | |
| README.zh.md | 7 ay önce | |
| cache.go | 2 ay önce | |
| config.go | 7 ay önce | |
The Cache Plugin is a high-performance caching solution for AI API requests that helps reduce latency and costs by storing and reusing responses for identical requests. It supports both in-memory caching and Redis, making it suitable for distributed deployments.
{
"model": "gpt-4",
"type": 1,
"plugin": {
"cache": {
"enable": true,
"ttl": 300,
"item_max_size": 1048576,
"add_cache_hit_header": true,
"cache_hit_header": "X-Cache-Status"
}
}
}
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
enable |
bool | Yes | false | Whether to enable the Cache plugin |
ttl |
int | No | 300 | Time-to-live for cached items (in seconds) |
item_max_size |
int | No | 1048576 (1MB) | Maximum size of a single cached item (in bytes) |
add_cache_hit_header |
bool | No | false | Whether to add a header indicating cache hit |
cache_hit_header |
string | No | "X-Aiproxy-Cache" | Name of the cache hit header |
The plugin generates cache keys based on:
This ensures identical requests hit the cache while different requests don't interfere with each other.
The plugin uses a two-tier caching strategy:
Request Phase:
Response Phase:
{
"plugin": {
"cache": {
"enable": true,
"ttl": 60,
"item_max_size": 524288,
"add_cache_hit_header": true
}
}
}
When add_cache_hit_header is enabled:
Cache Hit:
X-Aiproxy-Cache: hit
Cache Miss:
X-Aiproxy-Cache: miss