回收 TB:使用 TLRU 优化 Android 图片缓存
In a previous post, we discussed Project Bonsai, our initiative to reduce the Grab app’s download size. We successfully reduced the Android Application Package (APK) download size by 26%. This reduction offers a substantial advantage: it minimizes download friction, allowing users to download the app, even on slower networks. However, the battle for storage doesn’t end after installation.
在之前的文章中,我们讨论了 Project Bonsai,这是我们减少 Grab 应用下载大小的举措。我们成功地将 Android Application Package (APK) 下载大小减少了 26%。这一减少提供了实质性优势:它最小化了下载摩擦,即使在较慢的网络上,用户也能下载应用。然而,存储之战在安装后并未结束。
The Grab app includes a wide range of features and workflows that heavily depend on image content, particularly in services like transportation and e-commerce. Although some images are packaged within the app binary, a large majority are downloaded from Grab’s server at runtime. To optimize the app’s performance and minimize server expenses, the downloaded images are cached in the app’s storage. This reduces both load times and traffic to Grab’s image server, resulting in better user experience and lower costs. Although we use Least Recently Used (LRU) cache to manage storage, many images can remain in the app storage for extended periods, even if they are no longer relevant.
Grab 应用包含多种功能和工作流程,这些功能和工作流程在很大程度上依赖于图像内容,特别是在交通和电子商务等服务中。尽管一些图像打包在应用二进制文件中,但绝大多数图像在运行时从 Grab’s server 下载。为了优化应用性能并最小化服务器开销,下载的图像被缓存在应用的存储中。这减少了加载时间和对 Grab 图像服务器的流量,从而带来更好的用户体验和更低的成本。尽管我们使用 Least Recently Used (LRU) 缓存来管理存储,但许多图像即使不再相关,也可能在应用存储中保留很长时间。
This blog details how we addressed this challenge in our Grab Android app by evolving our standard LRU cache into a Time-Aware Least Recently Used (TLRU) cache. This evolution allows us to reclaim storage space without compromising user experience or increasing server costs.
本文详细介绍了我们如何通过将标准的 LRU 缓存演变为 Time-Aware Least Recently Used (TLRU) 缓存,来解决 Grab Android 应用中的这一挑战。这种演变使我们能够在不损害用户体验或增加服务器成本的情况下回收存储空间。
Understanding LRU cache limitations
理解 LRU 缓存的局限性
Note: In this article, when “cache” or “image cache” is mentioned, it specifically refers to disk ...