rednaks/django-ip-geolocation

Idea of retrieving geolocation data from cookie if present

girishkumarkh opened this issue · 2 comments

@rednaks have you thought about retrieving the geolocation from the cookie so that we don't need to call the API every single request?

Use case: a typical user will visit multiple pages per site and it's very unlikely their geolocation will change on every request. But calling the API on every single request can be changed to only when the cookie doesn't exist.

Hello @girishkumarkh , thanks for the suggestion.

what do you actually mean by take if from the cookies ?
Your description sounds to me like you want a cache for the geolocation data. I already opened an issue for that you can check #10 but I'm wondering, do you use cache cause still have no idea how to implement something that would be generic for everyone, even those who don't use a django cache ...

~r

yea kinda like cache but mostly not using cookies as data storage

User have to add this in settings:

ENABLE_COOKIE = True (has to be true for cache to work)
CACHE_IN_COKKIE = True

The flow will look this:
START
┣ User makes a request
┣ Check IF the user has geolocation in a cookie and is not older than 15 days
┃ ┗ YES: Use the geolocation from the cookie and no API calls made
┃ ┗ NO: Call the API from one of the backends and create the cookie as per process_response function
END