API

Use these tools to interact with django-cachalot, especially if you face raw queries limits or if you need to create a cache key from the last table invalidation timestamp.

cachalot.api.invalidate(*tables_or_models, **kwargs)[source]

Clears what was cached by django-cachalot implying one or more SQL tables or models from tables_or_models. If tables_or_models is not specified, all tables found in the database (including those outside Django) are invalidated.

If cache_alias is specified, it only clears the SQL queries stored on this cache, otherwise queries from all caches are cleared.

If db_alias is specified, it only clears the SQL queries executed on this database, otherwise queries from all databases are cleared.

Parameters:
  • tables_or_models (tuple of strings or models) – SQL tables names or models (or combination of both)
  • cache_alias (string or NoneType) – Alias from the Django CACHES setting
  • db_alias (string or NoneType) – Alias from the Django DATABASES setting
Returns:

Nothing

Return type:

NoneType

cachalot.api.get_last_invalidation(*tables_or_models, **kwargs)[source]

Returns the timestamp of the most recent invalidation of the given tables_or_models. If tables_or_models is not specified, all tables found in the database (including those outside Django) are used.

If cache_alias is specified, it only fetches invalidations in this cache, otherwise invalidations in all caches are fetched.

If db_alias is specified, it only fetches invalidations for this database, otherwise invalidations for all databases are fetched.

Parameters:
  • tables_or_models (tuple of strings or models) – SQL tables names or models (or combination of both)
  • cache_alias (string or NoneType) – Alias from the Django CACHES setting
  • db_alias (string or NoneType) – Alias from the Django DATABASES setting
Returns:

The timestamp of the most recent invalidation

Return type:

float