<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ravi Gupta on Medium]]></title>
        <description><![CDATA[Stories by Ravi Gupta on Medium]]></description>
        <link>https://medium.com/@ravigupta049?source=rss-7f7aee7ad40f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xNgeLRyJz7TwoEkB6HqI1w.png</url>
            <title>Stories by Ravi Gupta on Medium</title>
            <link>https://medium.com/@ravigupta049?source=rss-7f7aee7ad40f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 21:28:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ravigupta049/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Handling multiple caches in App]]></title>
            <link>https://medium.com/swiggy-bytes/handling-multiple-caches-in-app-cf1e98b74e3b?source=rss-7f7aee7ad40f------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf1e98b74e3b</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiggy-mobile]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Ravi Gupta]]></dc:creator>
            <pubDate>Thu, 01 Sep 2022 08:04:38 GMT</pubDate>
            <atom:updated>2022-09-01T08:04:38.285Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*qmJnd526kEss1SV7_7rKNw.png" /></figure><p>Every app requires some sort of caching mechanism for the assets to provide seamless user experience. Downloading each asset every time can be expensive and users will see some delays in the loading of those assets. Developers use different types of caching mechanisms like disk caching, LRU caching, database, etc.</p><p>Based on different requirements we take a call on which mechanism to use. But what if we want to use multiple mechanisms to cache different types of data? How are we going to handle all those?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*kXmRYbmEYhP-JnVh" /></figure><p>Well, don’t worry, in this article we are going to handle those cases. How we can effectively handle different types of caching mechanisms and make space for others as well 😉.</p><h3>Implementation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ta1NUvT42aLq5I7IkByNBw.png" /><figcaption>High Level Diagram of the system</figcaption></figure><p>So let’s introduce the way we handle it. The whole system will include 3 layers that will serve different purposes. This approach can be implemented on a platform where we want to do any type of caching.</p><h4>1. Utils</h4><p>Each type of asset will have its util to handle specific functionalities related to that type. The functionalities include downloading, parsing, etc.</p><p>These utils will be used to fetch the respective assets from the assets manager. The app will not directly interact with the assets manager.</p><p>Let’s take an example for image util. This util will download the image if not present by calling the get data of assets manager. Post downloading the image it will pass the raw data to the assets manager for storing it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bbdcfd128983d54647ad091170f13b06/href">https://medium.com/media/bbdcfd128983d54647ad091170f13b06/href</a></iframe><h4>2. Assets Manager</h4><p>This will be the middle layer which will interact with the utils and the different types of storage i.e caching mechanisms. The whole purpose of this manager will be to check which type of caching we need to use based on the storage type.</p><p>Storage type will tell what type of caching mechanisms are present.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7216456fbc015de2040b060c6edc7e48/href">https://medium.com/media/7216456fbc015de2040b060c6edc7e48/href</a></iframe><p>The assets manager will have common methods to store and retrieve data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/989245e5617ba6da903d6e3c8a935b5b/href">https://medium.com/media/989245e5617ba6da903d6e3c8a935b5b/href</a></iframe><p>When the utils call these methods the assets manager will call the respective methods of caching layers based on storage type.</p><h4>3. Caching Layer</h4><p>This layer will include all the caching mechanisms that we will be using. It can be disk or LRU or database. This layer will only store data in raw form and will be agnostic of the data types.</p><p>We used different caching mechanisms based on different requirements. When we want the assets to be permanently available we use disk caching. But if we want to cache data that is not permanent we use the LRU caching mechanism. <br>For LRU caching also, we have different caches for different asset types like image, lottie, etc.</p><p><strong>Disk Caching</strong></p><p>It’s a type of caching mechanism where we store the data directly into the disk. We read/write the data from the disk.</p><p><strong>LRU Caching</strong></p><p>Least Recently Used(LRU) caching is a caching mechanism where we store the data in memory with the defined size of the elements it can hold. Once the space is full it removes the element which is least recently used to make space for the new element.</p><p>In our case</p><ul><li><strong>For Image:</strong> We are using both the caching mechanisms i.e disk and LRU.</li><li><strong>For Rendering Animations:</strong> We are using LRU caching.</li><li><strong>For Rendering Videos:</strong> We are using our own Disk cache. (<a href="https://bytes.swiggy.com/video-stories-and-caching-mechanism-ios-61fc63cc04f8">Blog</a>)</li></ul><p>This article covers on handling the different types of cache mechanism. It does not cover the cache implementation. <br>For more details on implementation you can refer below articles.</p><ul><li><a href="https://bytes.swiggy.com/video-stories-and-caching-mechanism-ios-61fc63cc04f8">Video Stories and Caching</a></li><li><a href="https://bytes.swiggy.com/insight-into-swiggys-new-multimedia-card-3229d7b4ae75">Insight into Swiggy’s new Multimedia Card</a></li></ul><p>In this way, each layer has its responsibilities and is mutually exclusive. In the future, if we want to introduce another caching mechanism we can do it without changing the existing flow. We just need to add the type and the flow remains the same.</p><p>All the APIs exposed between the layers will be generic and driven by the protocols so that there is no change in the contract between them.</p><p><strong>Sequence diagram:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zIBSDcfkoB-rlGx7" /><figcaption>Sequence of steps involved</figcaption></figure><h3><strong>Conclusion</strong></h3><p>As every layer is independent of other layers we can easily plug in or plug out any caching mechanism we want with minimum code changes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf1e98b74e3b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swiggy-bytes/handling-multiple-caches-in-app-cf1e98b74e3b">Handling multiple caches in App</a> was originally published in <a href="https://medium.com/swiggy-bytes">Swiggy Bytes — Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>