如何缓存基于位置的数据库查询?

发布于 2025-01-05 11:07:25 字数 306 浏览 3 评论 0原文

因此,我正在构建一个应用程序,它使用纬度/经度坐标将位置保存到数据库中。用户可以使用创建日期(“最近”)或位置(“附近”)来获取这些记录。我现在的目标是实现缓存以加快应用程序的速度。

对于最近的部分,我猜它非常简单,只需将查询缓存一分钟左右,但对于基于位置的查询,这没有任何意义。我目前正在从地图中获取用户位置,并从数据库中获取 25 个最近的位置。由于用户可以自由移动地图(iOS),因此两次击中完全相同的位置的机会是不存在的,这让我相信我在这里使用了错误的方法。

我将如何安排我的数据和查询,以便用户仍然可以根据其位置获取结果,但仍然可以利用一些缓存。这可能吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

上课铃就是安魂曲 2025-01-12 11:07:25

您可能必须将地图划分为某种形式的网格系统(想象一下覆盖棋盘),以便点的集合位于同一区域。这会给你一些确定的东西来锁定缓存(或者至少是缓存所在的容器)。您可以使用第二组较大的方块来查找“接近”的项目。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文