Caching

Cache management utilities for Proxy objects.

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

  • Retrieve and cache Proxies owned by a user profile

  • Retrieve and cache Proxies shared with a user profile

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

  • Invalidate caches for owned, shared, and available Proxies

  • Invalidate all Proxy-related caches for a user profile

Functions:

  • get_cached_proxies_owned_by_user_profile(user_profile)

  • invalidate_cached_proxies_owned_by_user_profile(user_profile)

  • get_cached_proxies_shared_with_user_profile(user_profile)

  • invalidate_cached_proxies_shared_with_user_profile(user_profile)

  • get_cached_proxies_available_to_user_profile(user_profile)

  • invalidate_cached_proxies_available_to_user_profile(user_profile)

  • invalidate_all_cached_proxies_for_user_profile(user_profile)

Dependencies:

  • Django ORM

  • smarter.lib.cache.cache_results

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

  • smarter.apps.proxy.models.Proxy

  • smarter.apps.proxy.serializers.ProxySerializer

smarter.apps.proxy.caching.get_cached_proxies_available_to_user_profile(user_profile)[source]

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

This function returns a queryset of Proxy objects that are available to the specified user profile, which may include both owned and shared Proxies. 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 Proxies should be retrieved.

Returns:

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

Return type:

QuerySet

>>> user_profile = UserProfile.objects.get(pk=1)
>>> available_proxies = get_cached_proxies_available_to_user_profile(user_profile)
>>> for proxy in available_proxies:
...     print(proxy.name)

See also

smarter.apps.proxy.caching.get_cached_proxies_owned_by_user_profile(user_profile)[source]

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

This function returns a queryset of Proxy 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 Proxies should be retrieved.

Returns:

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

Return type:

QuerySet

>>> user_profile = UserProfile.objects.get(pk=1)
>>> proxies = get_cached_proxies_owned_by_user_profile(user_profile)
>>> for proxy in proxies:
...     print(proxy.name)

See also

smarter.apps.proxy.caching.get_cached_proxies_shared_with_user_profile(user_profile)[source]

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

This function returns a queryset of Proxy 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 Proxies should be retrieved.

Returns:

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

Return type:

QuerySet

>>> user_profile = UserProfile.objects.get(pk=1)
>>> shared_proxies = get_cached_proxies_shared_with_user_profile(user_profile)
>>> for proxy in shared_proxies:
...     print(proxy.name)

See also

smarter.apps.proxy.caching.invalidate_all_cached_proxies_for_user_profile(user_profile)[source]

Invalidate all cached Proxy querysets related to the given UserProfile.

This function invalidates the caches for all Proxy querysets that are related to the specified user profile, including owned, shared, and available Proxies. 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 Proxy querysets.

Returns:

None

Return type:

None

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

See also

smarter.apps.proxy.caching.invalidate_cached_proxies_available_to_user_profile(user_profile)[source]
Return type:

None

smarter.apps.proxy.caching.invalidate_cached_proxies_owned_by_user_profile(user_profile)[source]
Return type:

None

smarter.apps.proxy.caching.invalidate_cached_proxies_shared_with_user_profile(user_profile)[source]
Return type:

None