Caching

Cache management utilities for Secret objects.

This module provides functions for efficient type-annotated retrieval and caching of Secret querysets. It includes utilities to:

  • Retrieve and cache Secrets owned by a user profile

  • Retrieve and cache Secrets shared with a user profile

  • Retrieve and cache Secrets available to a user profile (owned or shared)

  • Invalidate caches for owned, shared, and available Secrets

  • Invalidate all Secret-related caches for a user profile

Functions:

  • get_cached_secrets_owned_by_user_profile(user_profile)

  • invalidate_cached_secrets_owned_by_user_profile(user_profile)

  • get_cached_secrets_shared_with_user_profile(user_profile)

  • invalidate_cached_secrets_shared_with_user_profile(user_profile)

  • get_cached_secrets_available_to_user_profile(user_profile)

  • invalidate_cached_secrets_available_to_user_profile(user_profile)

  • invalidate_all_cached_secrets_for_user_profile(user_profile)

Dependencies:

  • Django ORM

  • cache_results.cache_results

  • smarter.apps.account.models.user_profile.UserProfile

  • smarter.apps.secret.models.Secret

smarter.apps.secret.caching.get_cached_secrets_available_to_user_profile(user_profile)[source]

Retrieve the Secrets available to the given UserProfile, using caching to optimize performance.

This function returns a queryset of Secret objects that are available to the specified user profile, which may include both owned and shared Secrets. The results are cached to reduce database queries and improve performance. If the cache is invalidated, the queryset is fetched from the database again and re-cached.

Parameters:

user_profile (UserProfile) – The user profile whose available Secrets should be retrieved.

Returns:

A Django queryset containing the Secret objects available to the user.

Return type:

QuerySet

>>> user_profile = UserProfile.objects.get(pk=1)
>>> available_secrets = get_cached_secrets_available_to_user_profile(user_profile)
>>> for bot in available_secrets:
...     print(bot.name)

See also

smarter.apps.secret.caching.get_cached_secrets_owned_by_user_profile(user_profile)[source]

Retrieve the Secrets owned by the given UserProfile, using caching to optimize performance.

This function returns a queryset of Secret objects that are owned by the specified user profile. The results are cached to reduce database queries and improve performance. If the cache is invalidated, the queryset is fetched from the database again and re-cached.

Parameters:

user_profile (UserProfile) – The user profile whose owned Secrets should be retrieved.

Returns:

A Django queryset containing the Secret objects owned by the user.

Return type:

QuerySet

>>> user_profile = UserProfile.objects.get(pk=1)
>>> secrets = get_cached_secrets_owned_by_user_profile(user_profile)
>>> for bot in secrets:
...     print(bot.name)

See also

smarter.apps.secret.caching.get_cached_secrets_shared_with_user_profile(user_profile)[source]

Retrieve the Secrets shared with the given UserProfile, using caching to optimize performance.

This function returns a queryset of Secret objects that are shared with the specified user profile. The results are cached to reduce database queries and improve performance. If the cache is invalidated, the queryset is fetched from the database again and re-cached.

Parameters:

user_profile (UserProfile) – The user profile whose shared Secrets should be retrieved.

Returns:

A Django queryset containing the Secret objects shared with the user.

Return type:

QuerySet

>>> user_profile = UserProfile.objects.get(pk=1)
>>> shared_secrets = get_cached_secrets_shared_with_user_profile(user_profile)
>>> for bot in shared_secrets:
...     print(bot.name)

See also

smarter.apps.secret.caching.invalidate_all_cached_secrets_for_user_profile(user_profile)[source]

Invalidate all cached Secret querysets related to the given UserProfile.

This function invalidates the caches for all Secret querysets that are related to the specified user profile, including owned, shared, and available Secrets. This is useful when a change occurs that may affect any of these querysets, ensuring that subsequent calls will fetch fresh data from the database.

Parameters:

user_profile (UserProfile) – The user profile for which to invalidate cached Secret querysets.

Returns:

None

Return type:

None

>>> user_profile = UserProfile.objects.get(pk=1)
>>> invalidate_all_cached_secrets_for_user_profile(user_profile)

See also

smarter.apps.secret.caching.invalidate_cached_secrets_available_to_user_profile(user_profile)[source]

Drop the cached queryset of Secrets available to (owned or shared) a user profile.

The next get_cached_secrets_available_to_user_profile() call queries the database again.

Parameters:

user_profile (UserProfile) – The user profile whose cached queryset is dropped.

Return type:

None

smarter.apps.secret.caching.invalidate_cached_secrets_owned_by_user_profile(user_profile)[source]

Drop the cached queryset of Secrets owned by a user profile.

The next get_cached_secrets_owned_by_user_profile() call queries the database again.

Parameters:

user_profile (UserProfile) – The user profile whose cached queryset is dropped.

Return type:

None

smarter.apps.secret.caching.invalidate_cached_secrets_shared_with_user_profile(user_profile)[source]

Drop the cached queryset of Secrets shared with a user profile.

The next get_cached_secrets_shared_with_user_profile() call queries the database again.

Parameters:

user_profile (UserProfile) – The user profile whose cached queryset is dropped.

Return type:

None