Arvid Janson
Arvid Janson

Reputation: 1034

How do I cache location based database queries?

So, I'm building an application which save locations to a database using lat/lon coordinates. Users can the fetch these records using either creation date ("recent") or position ("nearby"). My goal now is to implement caching to speed up the app.

For the recent section, I'm guessing that it's pretty simple, just cache the query for a minute or so, but for the location based queries, this would make no sense. I'm currently getting the users location from the map, and the fetching the 25 closest locations from the DB. As the user can move the map freely (iOS), the chance of hitting the exact same spot twice is non existing, which makes me believe that I'm using the wrong approach here.

How would I arrange my data, and queries, so that users can still get results based on their location, but still take advantage of some caching. Is this even possible?

Upvotes: 1

Views: 736

Answers (1)

Chriseyre2000
Chriseyre2000

Reputation: 2053

You may have to divide the map into some form of grid system (think overlaying a chessboard) so that a collection of points are in the same area. This would give you something definate to key the cache with (or at least the bins that the caches live in). You could have a second set of larger squares to find "close" items.

Upvotes: 1

Related Questions