I have a requirement to create a java cache which holds all the cities and airports. So, if i query the cache for a location, lets say a city, it should return all the airports in that city and if I query a location which is an airport, i should get back that airport. Also, each location has to be stored as a byte array in cache.(as the exposed interface for querying the cache has byte[] as the parameter for location) Other considerations are:
- The retrieval has to be very fast, as fast as possible
- The cache is loaded only once at system startup.It doesn't change after getting loaded.
- As its loaded only once, we can keep it sorted if that speeds up the retrieval.
What I have got so far:
Approach 1
Create a thin wrapper over byte[] array, lets say ByteWrapper. Put each location(both airports and cities) as a key in map(TreeMap?). Use lists of ByteWrapper(containing airports where ever applicable) as values.
Approach 2
Create multi dimensional byte[] array which is sorted on location. Its essentially a map. Then use binary search to locate the key and return results.
What approach would you suggest? Please let me know in case you have better ideas Thanks