<?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 Zi Lam on Medium]]></title>
        <description><![CDATA[Stories by Zi Lam on Medium]]></description>
        <link>https://medium.com/@quilam.ct?source=rss-ab3cbe8c2330------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*3hGsJyyzUClXhM_e.</url>
            <title>Stories by Zi Lam on Medium</title>
            <link>https://medium.com/@quilam.ct?source=rss-ab3cbe8c2330------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 15:08:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@quilam.ct/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[Improve performance s3 and ActiveStorage Ruby on rails]]></title>
            <link>https://medium.com/@quilam.ct/improve-performance-s3-and-activestorage-ruby-on-rails-97de98bc4537?source=rss-ab3cbe8c2330------2</link>
            <guid isPermaLink="false">https://medium.com/p/97de98bc4537</guid>
            <dc:creator><![CDATA[Zi Lam]]></dc:creator>
            <pubDate>Fri, 17 Feb 2023 07:58:28 GMT</pubDate>
            <atom:updated>2023-02-17T07:58:28.473Z</atom:updated>
            <content:encoded><![CDATA[<p>In ActiveStorage, you can cache the URL of a file to avoid having to re-fetch it from the storage service every time it is needed. This can improve the performance of your application by reducing the number of requests to the storage service.</p><p>To cache the URL of a file, you can use the service_url method on the ActiveStorage::Attachment object. This method returns the URL of the file in the storage service.</p><p>Here’s an example of how to use service_url to cache the URL of a file:</p><pre>class MyModel &lt; ApplicationRecord<br>  has_one_attached :file<br><br>  def file_url<br>    Rails.cache.fetch([file.cache_key, &#39;url&#39;]) do<br>      file.service_url<br>    end<br>  end<br>end</pre><p>In this example, the file_url method is defined on a model that has a has_one_attached association with a file. The method uses Rails.cache.fetch to cache the URL of the file, using the cache key of the attachment and the string &#39;url&#39;. If the URL is already cached, it is returned from the cache. Otherwise, the service_url method is called to fetch the URL from the storage service and then cached.</p><p>You can adjust the cache duration and other options by passing additional arguments to Rails.cache.fetch. For example, you can specify the expiration time of the cache:</p><pre>Rails.cache.fetch([file.cache_key, &#39;url&#39;], expires_in: 1.hour) do<br>  file.service_url<br>end</pre><p>In this example, the cache will expire after 1 hour, so the service_url method will be called again to fetch the URL after the expiration time has passed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97de98bc4537" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>