Caching stores a language model’s response so repeated identical requests can be served quickly without querying the provider again, saving time and money. In DSPy, caching is enabled by default; disable it when checking response consistency or execution time. section 2.4.4
Listing 2.10 Disabling the DSPy cache mechanism
dspy.configure_cache( #1
enable_disk_cache=False,
enable_memory_cache=False
)
lm = dspy.LM('openai/gpt-4o', cache=True, temperature=0.99) #2
dspy.configure(lm=lm)
prog = dspy.Predict("question -> answer")
print(prog(question="Compose a 5-line poem about space")) #3
print(prog(question="Compose a 5-line poem about space")) #4
DSPy caching requires both global caching and the LM’s cache setting to be enabled. This example disables both globally, then calls the same program twice. section 2.4.4





































