This blog explains what cache busting, how it works in Salesforce, what are the common cache busting techniques and best practices that followed in Salesforce.
In one of our recent projects, I faced a Cache issue at the Salesforce screen level and it is reported one of the critical issue from our client side were they can't see the recent release UI features in the Salesforce screen level. This led to confusion & frustrating to them whether the feature is released or not and what happening in the system since I already communicated that the new feature were live and ready for use.
For this issue, I was explored various solutions within the Salesforce, I found no direct solutions for Cache Busting. This triggered us to dive deeper and found our own approach to ensure always experience the recent release version of that feature after every new release to end users. In addition, I was went through many forums and I didn't get any clear idea about this issue. So, I decided to provide the complete idea(to someone who looking this like me) that I researched and collected over a days about how can we do Cache Busting in Salesforce.
In this blog, I will walk through how I addressed to clients for resolving the Cache Busting challenge and what worked, what didn't and the strategy that I followed to achieve the solution. Before you dive in, take a fresh breath, relax, and enjoy the read.
Firstly, you have to understand what Cache is & how it is working in the browser, then you can easily understand what Cache Busting is and how it works.
Cache is a temporary storage system that saves our recent data's that fetched from database which is used serve more quickly if you are requesting the same kind of data from database. It is effectively used to increase the performance, reduce loading time and minimize the repeated calls to access data from database.
Instead of getting the same data from database every time, it stores the data at first request and return the same for all further attempts if it is exist in the Cache. The below picture explains you easily how caching works.
At first request, it checks the Cache server and there is no data. Then it requests from the actual server and the data is retrieved from actual server, it stores in the Cache server.
In the next request, the system checks the cache server. Since the data from the first request is already stored there, it retrieves the data directly from the cache instead of the actual server. As a result, the same data from the initial request is returned. This process is known as caching.
Cache Busting is the technology which is used to force the browser to load the latest version of a file or data instead of getting the data from Cache. It is generic process were it suitable for all kind of technology for loading the recent versions of data.
At the first request, it works as it is which I discussed the Cache definition.
For the next all subsequent requests, it always request a new version of the file automatically by following the Cache Busting technique. This is the common technique followed across all platforms and it can be achieved by coding/automation. But coming into Salesforce, I don't have any direct options to force browsers to get latest version of files or data, and it has its own limits. But Salesforce offers various kind of features to showcase recent version of the changes in the browser by using the inbuilt features.
Please find the inbuilt hidden features which is used to showcase the recent changes in the UI without any force refreshing in browser in Salesforce.
You can always get latest version of data in the Salesforce UI by disabling the Enable secure and persistent browser caching to improve performance in the session settings configuration in the setup page. This is an org wide setting, and it significantly impacts the org performance. So, it only recommended to disable in Sandboxes for development purpose and highly not recommended for production environments where it cause the performance issue. By disabling this it increases the developer productivity in the development environment by showing the recent changes in the UI always.
You can clear the platform Caches by clearing the Session Caches or Org Caches. Org Caches can store the data stored across all users and sessions within the org and Session Caches can store the specific to the user's session. It can be used to reduce the loading time of database queries, to improve the scalability & performance and repetitive data access requests.
You can clear the app Caches in the Salesforce mobile app by navigating to the profile icon right side top corner -- Click the settings link -- Click Advanced option -- Click Clear Cached Data option to clear the app Caches. It can help users to resolve the issues like,
You can clear Caches,
It can be used to make sure always the end user is getting the recent changes in the UI by doing manual changes in the static resource configuration, visualforce page and lightning web components.
By following all Cache clear techniques, we can partially achieve Cache Busting in Salesforce but not completely. Our project is worthy example for that, since we can't do the first Cache clear option that we discussed above, because it is not recommended to production environment due to performance issue but it is good to have in sandboxes to see recent changes in the UI for developers. In addition, I already applied other related Cache techniques in LWC, Visualforce Page & Apex and we don't have any static resources to change the file names or version to get a recent changes. However, still it causing an issue in our project where it is not showing the new changes after a new release.
It is very frustrating, right? yes, by researching all this details I didn't found any inbuilt Salesforce features for achieving Cache Busting. But I found one manual process to achieve Cache Busting in browser level not within the Salesforce platform. Please find the steps below,
These steps are only for chrome browser,
If you want to clear other Caches then select respective checkboxes in the screen.
Based on this approach, I requested to client-side representative to educate end users to achieve Cache Busting via this manual technique to achieve Cache Busting for every new release or whenever they want to clear Caches to get recent changes.
To achieve Cache Busting is an easy and automated process for many platforms but not in the Salesforce Platform. Since, there are no direct feature available in Salesforce to achieve Cache Busting and I recommended this manual approach to run a business without any issues.
Hope, this blog helps you to give clear idea about Cache Busting and how it is achieved that I didn't get any forums or any websites. Hope you have a strong idea about Cache Busting by reading this blog. Stay tune and follow our blogs for future updates.