views:

43

answers:

2

Hello, I am planning to use Maxmind's DAT file to provide some basic geolocation capabilities in an ASP.NET MVC application I'm developing. The DAT file is approximately 17mb and I'm wondering what the best approach would be to load this in my application - obviously I don't want to load it every time some geographical information is required and am thinking the best course of action is to load it into a shared variable upon application start.

How has anyone else approached this? Any recommendations? Thanks

JP

+2  A: 

The HttpRuntime.Cache seems to me to be the best place you could persist this data. See here for info about how to add and delete stuff from the cache.

spender
+1 - exactly what i'd have suggested. in fact, this mechanism can be as simple or fully featured as you want. in my apps, i've evolved it to such a stage that lambda and anonymous functions take care of all my 'strongly typed' objects, so that a request for the cache either populates it or gets the contents for that given key. it's a strategy that definately needs planning but once your 'key' scheme is identified, it's a no-brainier. i can drop a link to my implementations of this (unit testable as it uses interfaces to a wrapper)
jim
Sweet, sounds like it will work a treat. Thanks!
JP
+2  A: 

Cache is a terrible place to store this. It can get wiped out without notice so you'll have to re-load it whenever it gets deleted.

Maxmind supplies a .NET API to deal with their DAT file. The one packed as a tar.gz (described as "Open source C# API for GeoIP City, Country, ISP, and more") already has an option to efficiently load the data into a private cache, e.g.:

var lookupService = new LookupService("path.to.my.dat", LookupService.GEOIP_MEMORY_CACHE);
Mauricio Scheffer
I have used this API with great success. It's really fast.
jessegavin