Suor / django-cacheops

A slick ORM cache with automatic granular event-driven invalidation.
BSD 3-Clause "New" or "Revised" License
2.12k stars 227 forks source link

Redis getting called too many times in a single API call. #468

Closed MahnoorShafique closed 11 months ago

MahnoorShafique commented 11 months ago

I am inheriting my classes in views from ModelViewSet . and using builtin for queryset and serializer class upon configuring django-cacheops I saw so many calls to ElastiCache in ELK server for a single transaction. What is the reason for this?

Suor commented 11 months ago

All cacheops calls are either get cache, set cache or cache invalidation, which happens upon save/delete signals.

You can:

MahnoorShafique commented 11 months ago

@Suor This is my viewset Class:

class BookViewSet(ModelViewSet):
    permission_classes = [IsAuthenticated | RetoolIPPermission | HasAPIKey]
    queryset = Book.objects.select_related("grade_subject").all()
    serializer_class = BookSerializer
    http_method_names = ["get"]

    filter_backends = [DjangoFilterBackend]
    filterset_class = BookFilter
below are models
class Book(TimeStampedModel):
     grade_subject = ForeignKey(GradeSubject, on_delete=SET_NULL, null=True)
         ... 
      other fields
       ....
class GradeSubject(TimeStampedModel):
    grade = ForeignKey(Grade, on_delete=SET_NULL, null=True)
    subject = ForeignKey(Subject, on_delete=SET_NULL, null=True)

image as you can see in image it calls db 1 time but calls redis 1960 times. I have implemented caching using django-cacheops. what's missing , I am unable to debug. Can you please guide?

Suor commented 11 months ago

All the advices stay the same, not sure what can I add to that. For now one cannot even say where these redis queries are coming from.