Skip to content

Can't access ring-specific attributes on a cached property #180

@striveforbest

Description

@striveforbest

I am writing a reports/calculations module and using ring to store the results of expensive calculations in redis.
I started with using classmethods and it worked as expected, I was able to access ring-specific attributes (has, key, etc) but with property I cannot seem to be able to.

Here is a simplified example:

from django_redis import get_redis_connection


redis_connection = get_redis_connection('default')


class ProductCalculations:
    """
    Generate business intelligence from an organizations Product data.
    """

    def __init__(self, organization):
        self.organization = organization

    def __ring_key__(self):
        """ Required for setting a correct cache key. """
        return self.organization

    @ring.redis(redis_connection, coder='pickle')
    @property
    def products(self) -> 'QuerySet[Product]':
        return Product.objects.filter(organization=self.organization)

    @ring.redis(redis_connection, coder='pickle')
    @property
    def product_count(self) -> int:
        return self.products.count()

Upon inspecting the results, I can't seem to be able to access ring-specific attributes:

org = Organization.objects.all()[0]

calc = ProductCalculations(org)
calc.products

calc.products.has(o)

AttributeError: 'QuerySet' object has no attribute 'has'

Is this an expected behavior? How can I access ring-specific attributes on the cached property?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions