Abstract
Traditional Large Language Model (LLM) caching mechanisms rely on exact string matching or semantic similarity, both of which struggle with the dynamic nature of agentic workflows. Exact matching suffers from low hit rates in variable environments, while semantic caching often introduces "negative hits" by ignoring critical parameter differences. This paper introduces GenCache, a generative caching layer that identifies structural patterns in prompt-response pairs. By synthesizing customized responses through locally executed Python programs rather than static retrieval, GenCache achieves up to an 83% cache hit rate on complex benchmarks and reduces execution latency by approximately 34%.
Introduction
As LLM-based agents—such as automated web-shoppers and cloud diagnostic tools—become increasingly integrated into production environments, the efficiency of their execution becomes paramount. These agents frequently process prompts that exhibit Structured Regularity and Controlled Variability. For instance, an e-commerce agent might receive thousands of requests that follow a template (e.g., "Buy [Quantity] [Item]") where only the specific parameters change.
Existing caching solutions fail to address this middle ground. Exact Matching ensures correctness but misses nearly all hits in dynamic workflows. Semantic Caching uses vector similarity to increase hit rates but often overlooks subtle, crucial differences in parameters, leading to incorrect and potentially dangerous outputs. GenCache bridges this gap by moving from a "lookup" model to a "synthesis" model, teaching the cache to understand the underlying logic of the transformation.
The GenCache Architecture
GenCache replaces the traditional Key-Value store with a Prompt-to-Program architecture. The system operates through a four-stage lifecycle designed to automate the discovery and validation of structural patterns.
1. Prompt Clustering
When a cache miss occurs, the prompt and its corresponding LLM-generated response are stored as exemplars. GenCache utilizes embeddings of both the prompt and the response to group them into clusters. By incorporating response structure into the clustering logic, the system prevents prompts that appear semantically similar but require different logical actions from being incorrectly grouped.
2. Program Generation (CodeGenLLM)
Once a cluster reaches a sufficient threshold of exemplars, GenCache employs an LLM to infer the underlying transformation logic. The system generates a Python program—typically utilizing regular expressions—capable of extracting variables from a new prompt and formatting them into the required response structure.
3. Program Validation (ValidLLM)
To ensure reliability, a separate LLM validates the generated program against the existing exemplars in the cluster. The program is only "promoted" to the active cache if it consistently produces the correct output for all known examples, mitigating the risk of incorrect synthesis.
4. Runtime Execution
When a new prompt arrives, GenCache identifies the relevant cluster. If a validated program exists, the system executes the Python script locally. This bypasses the remote LLM call entirely, reducing response time from seconds to milliseconds while maintaining high precision.
Experimental Evaluation
The authors evaluated GenCache across a variety of synthetic and real-world agentic benchmarks:
- WebShop: A simulated e-commerce environment featuring over 12,000 crowd-sourced instructions.
- FLASH: A dataset of 298 real-world cloud incident diagnosis reports from Microsoft, representing complex, multi-step workflows.
- Synthetic Sets: Custom datasets designed to test variations in phrasing (e.g., "buy" vs. "purchase") to evaluate the system's robustness to synonymous variations.
Key Results
GenCache demonstrated significant improvements over traditional caching methods across several metrics:
- Hit Rate and Accuracy: The system achieved a 97% hit rate on simple parameterized datasets and an 83% hit rate on the complex WebShop dataset. Unlike semantic caches, which often suffered from 100% negative hits on non-repetitive data, GenCache maintained high precision by correctly mapping variables to outputs.
- Latency Reduction: By executing logic locally (~0.17s) instead of calling a remote LLM (~3.5s), GenCache reduced end-to-end execution latency by approximately 34% in agentic workflows like FLASH.
- Token Efficiency: The system yielded token savings between 35% and 73% per request, depending on task complexity. While there is an initial "warm-up" cost for program generation and validation, the long-term savings quickly amortize the initial investment.
Discussion and Limitations
GenCache represents a shift in caching philosophy: caching the logic of a translation rather than the result. However, the approach has limitations. It relies on structural consistency; if prompts are highly free-form or lack a discernible template (as in general-purpose chatbots), the regex-based programs fail to generalize. Additionally, while effective for reversible actions like "adding to a cart," applying generative caching to non-reversible actions (e.g., financial transactions) requires more stringent safety guardrails.
Future research directions include the implementation of complex branching logic (if-else structures) within the generated programs and the integration of feedback loops where downstream agent errors can trigger the automatic deletion or refinement of cached programs.
Summary updated