Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic caching not working in admin #287

Open
MarkBird opened this issue Jun 1, 2018 · 14 comments
Open

Automatic caching not working in admin #287

MarkBird opened this issue Jun 1, 2018 · 14 comments

Comments

@MarkBird
Copy link

MarkBird commented Jun 1, 2018

I'm using django-pyodbc-azure to connect to SQL Server. There isn't anything in the Cacheops docs that I could see that mentions anything about which backends are supported - but I've tried just adding

'*.*': {'ops': 'all', 'timeout': 60*60},

to the CACHEOPS config, which I think means everything should be automatically cached, and nothing gets cached at all, no errors, just nothing happens, all queries hit the database every time.

@Suor
Copy link
Owner

Suor commented Jun 2, 2018

DB backend doesn't matter. Maybe something else is misconfigured.

@Suor Suor closed this as completed Jun 2, 2018
@Suor Suor reopened this Jun 2, 2018
@MarkBird
Copy link
Author

MarkBird commented Jun 4, 2018

Thanks for replying. I'm wondering if the problem is that Django Admin seems to ignore bespoke object managers? Can you confirm that cacheops supports caching on the Admin site?

This probably isn't the right place to ask these kind of questions - should I just try StackOverflow instead?

@Suor
Copy link
Owner

Suor commented Jun 5, 2018

Oh, caching is disabled in admin explicitely.

@Suor
Copy link
Owner

Suor commented Jun 5, 2018

This is historical decision, I wonder whether I should turn it off in next major version, but for now it stays this way. To cache in admin you need to overwrite .get_queryset() method and call .cache() on queryset yourself.

@Suor Suor changed the title Automatic caching does nothing - could be a "not supported" issue but not documented. Automatic caching not working in admin Jun 5, 2018
@MarkBird
Copy link
Author

MarkBird commented Jun 5, 2018

Great, thanks for confirming - I've tested out non-admin queries and everything is working correctly and performance is great.

@Lepird
Copy link

Lepird commented Jun 9, 2018

Just adding a note on the caching of admin design choice, if you deem it good as an added feature maybe you can add it as an op per model ?

my logic here is that this would potentially be good for some models which are mainly config/setup related, but others like user model where admin is used to bulk view/alter users this would just flood redis with not needed data

@Suor
Copy link
Owner

Suor commented Jul 29, 2018

Thinking of more general approach to this. Using some form of aspects - mark them somehow and then configure to cache or not to cache things.

@gkapatia
Copy link

hey! any update on enabling caching for admin through settings?

@c0d5x
Copy link

c0d5x commented Aug 25, 2020

please!

@lampwins
Copy link
Contributor

@Suor I have run into this issue inadvertently by overriding get_queryset() but also using a m2m through model with an inline admin form.

Can you explain the reasoning as to why ModelAdmin querysets disable caching explicitly? I just want to better understand why this is today.

@paulonteri
Copy link

This is needed!

@physicalattraction
Copy link

This is historical decision, I wonder whether I should turn it off in next major version, but for now it stays this way. To cache in admin you need to overwrite .get_queryset() method and call .cache() on queryset yourself.
@Suor How would this work exactly? When I have this function, I get the error AttributeError: 'QuerySet' object has no attribute 'cache' in Django 3.2.16

    def get_queryset(self, request):
        queryset = super().get_queryset(request)
        queryset = queryset.cache()
        return queryset

@Suor
Copy link
Owner

Suor commented May 5, 2023

This might mean that cacheops was not installed properly, i.e. monkey patches were not applied, or this particular queryset does not descend from django.db.models.QuerySet, cacheops monkey patches that by adding .cache() to that among other things.

@rooterkyberian
Copy link

I just wasted some time on this as well. Went into bug tracker thinking maybe there is a bug in a recent version or something. At very least it should be mention in README, but I would also vote for giving people an option to enable it for admin operation as well. Even better, make it enabled by default, as it is better for admin to be first person to see cache misbehaving than end-user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants