I need to check the location of IP addresses during each request. Naturally, this is great for writing a small piece of custom middleware.
Given that this is python, is it better to initialize a GeoIP2 instance at the module level, or should I initialize it for the request?
I use django.contrib.gis.geoip2.GeoIP2one that uses itself: https://github.com/maxmind/GeoIP2-python
In particular: geoip2.database.Reader()
Looking at the source, first for the django module, I see that it has some caching options. I have the libmaxminddbC extension installed and according to the docs in the django source MODE_AUTO = 0, the default value is used, which translates it to try: MODE_MMAP_EXT, MODE_MMAP, MODE_FILEin that order.
Going to the C extension to load the database:
https://github.com/maxmind/MaxMind-DB-Reader-python/blob/master/maxminddb/extension/maxminddb.c
It seems to me that the file is not stored in memory, which makes sense, since this will be an unexpected side effect for those who use it. This also asks the question:
, mmdb , GeoIP2 /, , GeoIP2 , , , , , , - ?
- MODE_MEMORY?