title: How to memcache or store key value pair when key is in range and not a single value?
body: <p>We have a table in our database that has static ip range of cities and their ip address. It looks something like:</p>
  
  <hr>
  
  <p>IP-TO,    IP-FROM,   CITY</p>
  
  <p>100,          110,         A</p>
  
  <p>111,          168,         B</p>
  
  <p>...</p>
  
  <p>965,          1000,        Z</p>
  
  <p>I have mentioned sample data. The real data is huge with almost 64k rows in the table.</p>
  
  <p>For each user on our website, we determine their city from their IP address by executing sql query on sql express server.</p>
  
  <p>Since the data is static, for example every user with IP in range 100 to 110 belongs to city A, we are unnecessarily hitting database every time.</p>
  
  <p>We were thinking of caching every unique ip visit. For example:
  IP-100 mapped to A
  IP-101 mapped to A
  ...
  IP-110 mapped to A</p>
  
  <p>But this would create 64k keys in memcache and i feel there is no point of storing multiple keys that hold same value when we know the range.</p>
  
  <p>Can we somehow do this in a better way i.e. by minimum mem cache key or using a different approach altogether?</p>