public MicroCache getSegmentFor(final int ilon, final int ilat) {
        try {
            final int lonDegree = ilon / 1000000;
            final int latDegree = ilat / 1000000;
            OsmFile osmf = null;
            final OsmFile[] fileRow = fileRows[latDegree];
            final int ndegrees = fileRow == null ? 0 : fileRow.length;
            for (int i = 0; i < ndegrees; i++) {
                if (fileRow[i].lonDegree == lonDegree) {
                    osmf = fileRow[i];
                    break;
                }
            }
            if (osmf == null) {
                osmf = fileForSegment(lonDegree, latDegree);
                final OsmFile[] newFileRow = new OsmFile[ndegrees + 1];
                for (int i = 0; i < ndegrees; i++) {
                    newFileRow[i] = fileRow[i];
                }
                newFileRow[ndegrees] = osmf;
                fileRows[latDegree] = newFileRow;
            }
            currentFileName = osmf.filename;

            if (!osmf.hasData()) {
                return null;
            }

            MicroCache segment = osmf.getMicroCache(ilon, ilat);
            if (segment == null) {
                checkEnableCacheCleaning();
                segment = osmf.createMicroCache(ilon, ilat, dataBuffers, expCtxWay, waypointMatcher, directWeaving ? nodesMap : null);

                cacheSum += segment.getDataSize();
            } else if (segment.ghost) {
                segment.unGhost();
                ghostWakeup += segment.getDataSize();
            }
            return segment;
        } catch (IOException re) {
            throw new RuntimeException(re.getMessage(), re); // NOPMD
        } catch (RuntimeException re) {
            throw re;
        } catch (Exception e) {
            throw new RuntimeException("error reading datafile " + currentFileName + ": " + e, e);
        }
    }
Efficient cache or osmnodes

@author ab
main/src/main/java/cgeo/geocaching/brouter/mapaccess/NodesCache.java