Caching
Cache management utilities for PluginMeta objects.
This module provides functions for efficient type-annotated retrieval and caching of PluginMeta querysets. It includes utilities to:
Retrieve and cache PluginMetas owned by a user profile
Retrieve and cache PluginMetas shared with a user profile
Retrieve and cache PluginMetas available to a user profile (owned or shared)
Invalidate caches for owned, shared, and available PluginMetas
Invalidate all PluginMeta-related caches for a user profile
Functions:
get_cached_plugins_owned_by_user_profile(user_profile)
invalidate_cached_plugins_owned_by_user_profile(user_profile)
get_cached_plugins_shared_with_user_profile(user_profile)
invalidate_cached_plugins_shared_with_user_profile(user_profile)
get_cached_plugins_available_to_user_profile(user_profile)
invalidate_cached_plugins_available_to_user_profile(user_profile)
invalidate_all_cached_plugins_for_user_profile(user_profile)
Dependencies:
Django ORM
smarter.lib.cache.cache_results
smarter.apps.account.models.user_profile.UserProfile
smarter.apps.plugin.models.PluginMeta
smarter.apps.plugin.serializers.PluginMetaSerializer
- smarter.apps.plugin.caching.get_cached_plugins_available_to_user_profile(user_profile)[source]
Retrieve the PluginMetas available to the given UserProfile, using caching to optimize performance.
This function returns a queryset of PluginMeta objects that are available to the specified user profile, which may include both owned and shared PluginMetas. 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 PluginMetas should be retrieved.- Returns:
A Django queryset containing the PluginMeta objects available to the user.
- Return type:
>>> user_profile = UserProfile.objects.get(pk=1) >>> available_plugins = get_cached_plugins_available_to_user_profile(user_profile) >>> for bot in available_plugins: ... print(bot.name)
See also
invalidate_cached_plugins_available_to_user_profile()- Invalidate the cache for available PluginMetas of a user profile.
- smarter.apps.plugin.caching.get_cached_plugins_owned_by_user_profile(user_profile)[source]
Retrieve the PluginMetas owned by the given UserProfile, using caching to optimize performance.
This function returns a queryset of PluginMeta 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 PluginMetas should be retrieved.- Returns:
A Django queryset containing the PluginMeta objects owned by the user.
- Return type:
>>> user_profile = UserProfile.objects.get(pk=1) >>> plugins = get_cached_plugins_owned_by_user_profile(user_profile) >>> for bot in plugins: ... print(bot.name)
See also
invalidate_cached_plugins_owned_by_user_profile()- Invalidate the cache for owned PluginMetas of a user profile.
Retrieve the PluginMetas shared with the given UserProfile, using caching to optimize performance.
This function returns a queryset of PluginMeta 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 PluginMetas should be retrieved.- Returns:
A Django queryset containing the PluginMeta objects shared with the user.
- Return type:
>>> user_profile = UserProfile.objects.get(pk=1) >>> shared_plugins = get_cached_plugins_shared_with_user_profile(user_profile) >>> for bot in shared_plugins: ... print(bot.name)
See also
invalidate_cached_plugins_shared_with_user_profile()- Invalidate the cache for shared PluginMetas of a user profile.
- smarter.apps.plugin.caching.invalidate_all_cached_plugins_for_user_profile(user_profile)[source]
Invalidate all cached PluginMeta querysets related to the given UserProfile.
This function invalidates the caches for all PluginMeta querysets that are related to the specified user profile, including owned, shared, and available PluginMetas. 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 PluginMeta querysets.- Returns:
None
- Return type:
>>> user_profile = UserProfile.objects.get(pk=1) >>> invalidate_all_cached_plugins_for_user_profile(user_profile)
See also
invalidate_cached_plugins_owned_by_user_profile()- Invalidate the cache for owned PluginMetas of a user profile.invalidate_cached_plugins_shared_with_user_profile()- Invalidate the cache for shared PluginMetas of a user profile.invalidate_cached_plugins_available_to_user_profile()- Invalidate the cache for available PluginMetas of a user profile.
- smarter.apps.plugin.caching.invalidate_cached_plugins_available_to_user_profile(user_profile)[source]
- Return type:
- smarter.apps.plugin.caching.invalidate_cached_plugins_owned_by_user_profile(user_profile)[source]
- Return type:
- Return type: