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

Fixed bug in cache_page decorator #64

Merged
merged 4 commits into from
Mar 21, 2016

Conversation

ojomio
Copy link
Contributor

@ojomio ojomio commented Mar 18, 2016

It is necessary to introduce HTTP_X_FLAVOUR header before standard Django CacheMiddleware in request
and patch Vary: headers before standard Django CacheMiddleware in response as well

Thus, nesting flavour decorator inside cache decorator is not correct and we need two separate flavour decorators for caching with flavour

It is necessary to introduce `HTTP_X_FLAVOUR` header before standard Django `CacheMiddleware` in request
and patch `Vary:` headers before standard Django `CacheMiddleware` in response as well

Thus, nesting flavour decorator inside cache decorator is not correct and we need two separate flavour decorators for caching with flavour
@gregmuellegger
Copy link
Owner

Hi, thanks for the proposal. Splitting the middleware into two only makes sense if they are applied in different ends of the MIDDLEWARE_CLASSES setting. Can you describe/document, what would need to be changed in existing installations?

@ojomio
Copy link
Contributor Author

ojomio commented Mar 18, 2016

Oh, i just followed the django.cache logic. They also split the CacheMiddleware in two, though the later inherit CacheMiddleware from both. Here we actually split the @cache_page logic in two parts - because if we nest it like it was, HTTP_X_FLAVOUR header will be set after the standard CacheMiddleware makes the cache key.
I didn't think about applying it project-wide though. But now it makes perfect sense-we do need to use splitted middleware because middleware form a stack, but we need a queue in this case - mobile flavour , then cache fetch/store

@gregmuellegger
Copy link
Owner

Ok, that makes sense to me :) do you think we would need to adjust the README in this context. It currently states:

django-mobile is shipping with it's own implementation of cache_page to resolve this issue. Please use django_mobile.cache.cache_page instead of django's own cache_page decorator.

You can also use django's caching middlewares django.middleware.cache.UpdateCacheMiddleware and FetchFromCacheMiddleware like you already do. But to make them aware of flavours, you need to add django_mobile.cache.middleware.CacheFlavourMiddleware as second last item in the MIDDLEWARE_CLASSES settings, right before FetchFromCacheMiddleware.

@ojomio
Copy link
Contributor Author

ojomio commented Mar 18, 2016

Yep, i think we should but i'm currently afk

@gregmuellegger
Copy link
Owner

Alright, I'll keep the PR open until the docs are added.

@amrael
Copy link

amrael commented Mar 19, 2016

I'm delighted to see this bug is finally fixed and will be merged, although I fixed and sent almost the same PR two years ago and left unanswered since then ;)
#42

@ojomio
Copy link
Contributor Author

ojomio commented Mar 19, 2016

Oh, thanks! That makes me feel like i'm not an idiot and there is really a bug)

@gregmuellegger
Copy link
Owner

@amrael Sorry for that! I'm not actively using django-mobile myself, so this might have slipped past my unorganized self from two years ago 😁

Is one of you interested in taking over the maintenance of the project?

@ojomio
Copy link
Contributor Author

ojomio commented Mar 19, 2016

Uhm, thanks, but I don't think so. I'm good with proposing PRs)

@gregmuellegger
Copy link
Owner

😄 alright, keep it up.

@ojomio
Copy link
Contributor Author

ojomio commented Mar 19, 2016

Would you merge the code?

@amrael
Copy link

amrael commented Mar 19, 2016

@gregmuellegger no worries, I figured you're too busy to maintain it at that time.
I have no intention of taking over the project and it doesn't seem to require serious maintenance at the moment since I haven't come across any other problems over the past two years aside from this issue.

@ojomio
Copy link
Contributor Author

ojomio commented Mar 20, 2016

@gregmuellegger , does anything remain which blocks this pull-request from being merged?

gregmuellegger added a commit that referenced this pull request Mar 21, 2016
Fixed bug in `cache_page` decorator, splitting middleware in two
@gregmuellegger gregmuellegger merged commit 706eff7 into gregmuellegger:master Mar 21, 2016
gregmuellegger added a commit that referenced this pull request Mar 21, 2016
@gregmuellegger
Copy link
Owner

@ojomio Just released 0.7.0 including your changes: https://pypi.python.org/pypi/django-mobile/0.7.0

@ojomio
Copy link
Contributor Author

ojomio commented Mar 22, 2016

Thank you!

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

Successfully merging this pull request may close these issues.

3 participants