MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _generate_cache_key

Method _generate_cache_key

lib/sqlalchemy/sql/cache_key.py:347–387  ·  view source on GitHub ↗

return a cache key. The cache key is a tuple which can contain any series of objects that are hashable and also identifies this object uniquely within the presence of a larger SQL expression or statement, for the purposes of caching the resulting query. The

(self)

Source from the content-addressed store, hash-verified

345 return result
346
347 def _generate_cache_key(self) -> Optional[CacheKey]:
348 """return a cache key.
349
350 The cache key is a tuple which can contain any series of
351 objects that are hashable and also identifies
352 this object uniquely within the presence of a larger SQL expression
353 or statement, for the purposes of caching the resulting query.
354
355 The cache key should be based on the SQL compiled structure that would
356 ultimately be produced. That is, two structures that are composed in
357 exactly the same way should produce the same cache key; any difference
358 in the structures that would affect the SQL string or the type handlers
359 should result in a different cache key.
360
361 The cache key returned by this method is an instance of
362 :class:`.CacheKey`, which consists of a tuple representing the
363 cache key, as well as a list of :class:`.BindParameter` objects
364 which are extracted from the expression. While two expressions
365 that produce identical cache key tuples will themselves generate
366 identical SQL strings, the list of :class:`.BindParameter` objects
367 indicates the bound values which may have different values in
368 each one; these bound parameters must be consulted in order to
369 execute the statement with the correct parameters.
370
371 a :class:`_expression.ClauseElement` structure that does not implement
372 a :meth:`._gen_cache_key` method and does not implement a
373 :attr:`.traverse_internals` attribute will not be cacheable; when
374 such an element is embedded into a larger structure, this method
375 will return None, indicating no cache key is available.
376
377 """
378
379 bindparams: List[BindParameter[Any]] = []
380
381 _anon_map = anon_map()
382 key = self._gen_cache_key(_anon_map, bindparams)
383 if NO_CACHE in _anon_map:
384 return None
385 else:
386 assert key is not None
387 return CacheKey(key, bindparams)
388
389 @classmethod
390 def _generate_cache_key_for_object(

Callers 2

_generate_cache_keyMethod · 0.45

Calls 2

_gen_cache_keyMethod · 0.95
CacheKeyClass · 0.85

Tested by

no test coverage detected