class HasCacheKey: (source)
Known subclasses: sqlalchemy.orm.interfaces.CompileStateOption
, sqlalchemy.orm.interfaces.MapperProperty
, sqlalchemy.orm.path_registry.PathRegistry
, sqlalchemy.orm.path_registry.PathToken
, sqlalchemy.orm.util.AliasedInsp
, sqlalchemy.sql.base.CacheableOptions
, sqlalchemy.sql.cache_key.HasCacheKeyTraverse
, sqlalchemy.sql.cache_key.MemoizedHasCacheKey
, sqlalchemy.sql.cache_key.SlotsMemoizedHasCacheKey
, sqlalchemy.sql.sqltypes.TableValueType
, sqlalchemy.orm.strategy_options._LoadElement
, sqlalchemy.sql.selectable._MemoizedSelectEntities
Mixin for objects which can produce a cache key. This class is usually in a hierarchy that starts with the :class:`.HasTraverseInternals` base, but this is optional. Currently, the class should be able to work on its own without including :class:`.HasTraverseInternals`. .. seealso:: :class:`.CacheKey` :ref:`sql_caching`
Class Variable | __slots__ |
Undocumented |
Class Variable | inherit |
Indicate if this :class:`.HasCacheKey` instance should make use of the cache key generation scheme used by its immediate superclass. |
Class Method | _generate |
generate cache key dispatcher for a new class. |
Class Method | _generate |
Undocumented |
Method | _gen |
return an optional cache key. |
Method | _generate |
return a cache key. |
Class Variable | _generated |
Undocumented |
Class Variable | _hierarchy |
private attribute which may be set to False to prevent the inherit_cache warning from being emitted for a hierarchy of subclasses. |
Class Variable | _is |
Undocumented |
sqlalchemy.orm.interfaces.CompileStateOption
, sqlalchemy.orm.interfaces.MapperProperty
, sqlalchemy.orm.path_registry.PathRegistry
, sqlalchemy.orm.util.AliasedInsp
, sqlalchemy.sql.base.CacheableOptions
, sqlalchemy.sql.cache_key.MemoizedHasCacheKey
, sqlalchemy.sql.cache_key.SlotsMemoizedHasCacheKey
, sqlalchemy.orm.strategy_options._LoadElement
Undocumented
sqlalchemy.dialects.mssql.base.TryCast
, sqlalchemy.dialects.mysql.dml.Insert
, sqlalchemy.dialects.mysql.dml.Insert
, sqlalchemy.dialects.mysql.dml.Insert
, sqlalchemy.dialects.mysql.match
, sqlalchemy.dialects.postgresql.array
, sqlalchemy.dialects.postgresql.dml.Insert
, sqlalchemy.dialects.postgresql.dml.Insert
, sqlalchemy.dialects.postgresql.dml.Insert
, sqlalchemy.dialects.sqlite.dml.Insert
, sqlalchemy.dialects.sqlite.dml.Insert
, sqlalchemy.dialects.sqlite.dml.Insert
, sqlalchemy.orm.attributes.InstrumentedAttribute
, sqlalchemy.orm.descriptor_props.Composite
, sqlalchemy.orm.descriptor_props.Synonym
, sqlalchemy.orm.interfaces.StrategizedProperty
, sqlalchemy.orm.path_registry.CachingEntityRegistry
, sqlalchemy.orm.path_registry.PropRegistry
, sqlalchemy.orm.path_registry.RootRegistry
, sqlalchemy.orm.path_registry.SlotsEntityRegistry
, sqlalchemy.orm.path_registry.TokenRegistry
, sqlalchemy.orm.query.AliasOption
, sqlalchemy.sql.elements.AsBoolean
, sqlalchemy.sql.elements.AsBoolean
, sqlalchemy.sql.elements.BindParameter
, sqlalchemy.sql.elements.BooleanClauseList
, sqlalchemy.sql.elements.CollectionAggregate
, sqlalchemy.sql.elements.IndexExpression
, sqlalchemy.sql.elements.ReleaseSavepointClause
, sqlalchemy.sql.elements.RollbackToSavepointClause
, sqlalchemy.sql.elements.SavepointClause
, sqlalchemy.sql.functions.GenericFunction
, sqlalchemy.sql.functions.GenericFunction
, sqlalchemy.sql.schema.Column
, sqlalchemy.sql.selectable.Alias
, sqlalchemy.sql.selectable.Exists
, sqlalchemy.sql.selectable.Lateral
, sqlalchemy.sql.selectable.Lateral
, sqlalchemy.sql.selectable.NamedFromGrouping
, sqlalchemy.sql.selectable.NamedFromGrouping
, sqlalchemy.sql.selectable.NamedFromGrouping
, sqlalchemy.sql.selectable.ScalarSelect
, sqlalchemy.sql.selectable.ScalarSelect
, sqlalchemy.sql.selectable.Subquery
, sqlalchemy.orm.strategy_options._ClassStrategyLoad
, sqlalchemy.orm.strategy_options._TokenStrategyLoad
, sqlalchemy.orm.util._ORMJoin
Indicate if this :class:`.HasCacheKey` instance should make use of the cache key generation scheme used by its immediate superclass. The attribute defaults to ``None``, which indicates that a construct has not yet taken into account whether or not its appropriate for it to participate in caching; this is functionally equivalent to setting the value to ``False``, except that a warning is also emitted. This flag can be set to ``True`` on a particular class, if the SQL that corresponds to the object does not change based on attributes which are local to this class, and not its superclass. .. seealso:: :ref:`compilerext_caching` - General guideslines for setting the :attr:`.HasCacheKey.inherit_cache` attribute for third-party or user defined SQL constructs.
def _generate_cache_attrs(cls) ->
Union[ _CacheKeyTraversalDispatchType, Literal[ CacheConst.NO_CACHE]]
:
(source)
¶
generate cache key dispatcher for a new class. This sets the _generated_cache_key_traversal attribute once called so should only be called once per class.
def _generate_cache_key_for_object(cls, obj:
HasCacheKey
) -> Optional[ CacheKey]
:
(source)
¶
Undocumented
def _gen_cache_key(self, anon_map:
anon_map
, bindparams: List[ BindParameter[ Any]]
) -> Optional[ Tuple[ Any, ...]]
:
(source)
¶
sqlalchemy.orm.mapper.Mapper
, sqlalchemy.orm.path_registry.PathToken
, sqlalchemy.orm.util.Bundle
, sqlalchemy.sql.base.CacheableOptions
, sqlalchemy.sql.elements.BindParameter
, sqlalchemy.sql.functions.FunctionAsBinary
, sqlalchemy.sql.lambdas.LambdaElement
, sqlalchemy.sql.schema.Table
return an optional 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 cache key should be based on the SQL compiled structure that would ultimately be produced. That is, two structures that are composed in exactly the same way should produce the same cache key; any difference in the structures that would affect the SQL string or the type handlers should result in a different cache key. If a structure cannot produce a useful cache key, the NO_CACHE symbol should be added to the anon_map and the method should return None.
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 cache key should be based on the SQL compiled structure that would ultimately be produced. That is, two structures that are composed in exactly the same way should produce the same cache key; any difference in the structures that would affect the SQL string or the type handlers should result in a different cache key. The cache key returned by this method is an instance of :class:`.CacheKey`, which consists of a tuple representing the cache key, as well as a list of :class:`.BindParameter` objects which are extracted from the expression. While two expressions that produce identical cache key tuples will themselves generate identical SQL strings, the list of :class:`.BindParameter` objects indicates the bound values which may have different values in each one; these bound parameters must be consulted in order to execute the statement with the correct parameters. a :class:`_expression.ClauseElement` structure that does not implement a :meth:`._gen_cache_key` method and does not implement a :attr:`.traverse_internals` attribute will not be cacheable; when such an element is embedded into a larger structure, this method will return None, indicating no cache key is available.
sqlalchemy.sql.ddl.BaseDDLElement
private attribute which may be set to False to prevent the inherit_cache warning from being emitted for a hierarchy of subclasses. Currently applies to the :class:`.ExecutableDDLElement` hierarchy which does not implement caching.