MCPcopy
hub / github.com/langchain-ai/langchain / get_llm_cache

Function get_llm_cache

libs/core/langchain_core/globals.py:170–202  ·  view source on GitHub ↗

Get the value of the `llm_cache` global setting.

()

Source from the content-addressed store, hash-verified

168
169
170def get_llm_cache() -> "BaseCache":
171 """Get the value of the `llm_cache` global setting."""
172 try:
173 import langchain # type: ignore[import]
174
175 # We're about to run some deprecated code, don't report warnings from it.
176 # The user called the correct (non-deprecated) code path and shouldn't get warnings.
177 with warnings.catch_warnings():
178 warnings.filterwarnings(
179 "ignore",
180 message=(
181 "Importing llm_cache from langchain root module is no longer supported"
182 ),
183 )
184 # N.B.: This is a workaround for an unfortunate quirk of Python's
185 # module-level `__getattr__()` implementation:
186 # https://github.com/langchain-ai/langchain/pull/11311#issuecomment-1743780004
187 #
188 # Remove it once `langchain.llm_cache` is no longer supported, and
189 # once all users have migrated to using `set_llm_cache()` here.
190 #
191 # In the meantime, the `llm_cache` setting returns whichever of
192 # its two backing sources is truthy (not `None` and non-empty),
193 # or the old value if both are falsy. This accommodates users
194 # who haven't migrated to using `set_llm_cache()` yet.
195 # Those users are getting deprecation warnings directing them
196 # to use `set_llm_cache()` when they import `langhchain.llm_cache`.
197 old_llm_cache = langchain.llm_cache
198 except ImportError:
199 old_llm_cache = None
200
201 global _llm_cache
202 return _llm_cache or old_llm_cache

Callers 15

llm_cacheFunction · 0.90
_execute_testFunction · 0.90
test_mongodb_cacheFunction · 0.90
llm_cacheFunction · 0.90
_execute_testFunction · 0.90
test_mongodb_cacheFunction · 0.90
_resolve_cacheFunction · 0.90
generateMethod · 0.90
agenerateMethod · 0.90
_generate_with_cacheMethod · 0.90

Calls

no outgoing calls

Tested by 15

llm_cacheFunction · 0.72
_execute_testFunction · 0.72
test_mongodb_cacheFunction · 0.72
llm_cacheFunction · 0.72
_execute_testFunction · 0.72
test_mongodb_cacheFunction · 0.72
test_async_redis_cacheFunction · 0.72