Caching
Cache management utilities for AuthToken objects.
This module provides functions for efficient type-annotated retrieval and caching of AuthToken querysets. It includes utilities to:
Retrieve and cache AuthTokens owned by a user profile
Retrieve and cache AuthTokens shared with a user profile
Retrieve and cache AuthTokens available to a user profile (owned or shared)
Invalidate caches for owned, shared, and available AuthTokens
Invalidate all AuthToken-related caches for a user profile
Functions:
get_cached_authtokens_owned_by_user_profile(user_profile)
invalidate_cached_authtokens_owned_by_user_profile(user_profile)
get_cached_authtokens_shared_with_user_profile(user_profile)
invalidate_cached_authtokens_shared_with_user_profile(user_profile)
get_cached_authtokens_available_to_user_profile(user_profile)
invalidate_cached_authtokens_available_to_user_profile(user_profile)
invalidate_all_cached_authtokens_for_user_profile(user_profile)
Dependencies:
Django ORM
smarter.lib.cache.cache_results
smarter.apps.account.models.user_profile.UserProfile
smarter.apps.authtoken.models.AuthToken
smarter.apps.authtoken.serializers.AuthTokenSerializer
- smarter.lib.drf.caching.get_cached_authtokens_available_to_user_profile(user_profile)[source]
Retrieve the AuthTokens available to the given UserProfile, using caching to optimize performance.
This function returns a queryset of AuthToken objects that are available to the specified user profile, which may include both owned and shared AuthTokens. 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 AuthTokens should be retrieved.- Returns:
A Django queryset containing the AuthToken objects available to the user.
- Return type:
>>> user_profile = UserProfile.objects.get(pk=1) >>> available_authtokens = get_cached_authtokens_available_to_user_profile(user_profile) >>> for bot in available_authtokens: ... print(bot.name)
See also
invalidate_cached_authtokens_available_to_user_profile()- Invalidate the cache for available AuthTokens of a user profile.
- smarter.lib.drf.caching.get_cached_authtokens_owned_by_user_profile(user_profile)[source]
Retrieve the AuthTokens owned by the given UserProfile, using caching to optimize performance.
This function returns a queryset of AuthToken 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 AuthTokens should be retrieved.- Returns:
A Django queryset containing the AuthToken objects owned by the user.
- Return type:
>>> user_profile = UserProfile.objects.get(pk=1) >>> authtokens = get_cached_authtokens_owned_by_user_profile(user_profile) >>> for bot in authtokens: ... print(bot.name)
See also
invalidate_cached_authtokens_owned_by_user_profile()- Invalidate the cache for owned AuthTokens of a user profile.
Retrieve the AuthTokens shared with the given UserProfile, using caching to optimize performance.
This function returns a queryset of AuthToken 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 AuthTokens should be retrieved.- Returns:
A Django queryset containing the AuthToken objects shared with the user.
- Return type:
>>> user_profile = UserProfile.objects.get(pk=1) >>> shared_authtokens = get_cached_authtokens_shared_with_user_profile(user_profile) >>> for bot in shared_authtokens: ... print(bot.name)
See also
invalidate_cached_authtokens_shared_with_user_profile()- Invalidate the cache for shared AuthTokens of a user profile.
- smarter.lib.drf.caching.invalidate_all_cached_authtokens_for_user_profile(user_profile)[source]
Invalidate all cached AuthToken querysets related to the given UserProfile.
This function invalidates the caches for all AuthToken querysets that are related to the specified user profile, including owned, shared, and available AuthTokens. 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 AuthToken querysets.- Returns:
None
- Return type:
>>> user_profile = UserProfile.objects.get(pk=1) >>> invalidate_all_cached_authtokens_for_user_profile(user_profile)
See also
invalidate_cached_authtokens_owned_by_user_profile()- Invalidate the cache for owned AuthTokens of a user profile.invalidate_cached_authtokens_shared_with_user_profile()- Invalidate the cache for shared AuthTokens of a user profile.invalidate_cached_authtokens_available_to_user_profile()- Invalidate the cache for available AuthTokens of a user profile.
- smarter.lib.drf.caching.invalidate_cached_authtokens_available_to_user_profile(user_profile)[source]
- Return type:
- smarter.lib.drf.caching.invalidate_cached_authtokens_owned_by_user_profile(user_profile)[source]
- Return type:
- Return type: