A PHP or Python script periodically fetches a large dataset of IP addresses (/32 netmask) from a remote database. In-between fetches the dataset will be temporarily stored in APC or Memcached key store.
The main job of the script is to check if a given ip-address exists in the database/cache (think: "blacklist").
What would be the most efficient (performance wise) way to:
- Store the IP addresses in APC/Memcache
- Compare a given IP to the stored IP list.
What i have come up with so far:
Alternative 1 Store all IP addresses as a large array-list as the value of a single key in APC, then do a
if (in_array("192.168.0.1", $ip_list_from_cache))
Alternative 2 Store each IP as key-name in APC, then do a
if (apc_exists('192.168.0.1')
This is a large list and i want the compare check to be very fast.
Thanks in advance for any comments!