Use cases of Ephemeral Configuration in URLSession 📟

Chetan Aggarwal
2 min readMar 1, 2024

--

Here we will be discussing the use cases of ephemeral session configuration in the URLSession and some details about its persistence.

Prerequisite 📖:

  • You know the basic implementation of URL Session implementation in your project.
  • If you do not then don’t worry I got you covered, just go through this link.

What Apple says🧑🏻‍💻:

  • A session configuration that uses no persistent storage for caches, cookies, or credentials.
  • An ephemeral session configuration object is similar to a default session configuration (see default), except that the corresponding session object doesn’t store caches, credential stores, or any session-related data to disk. Instead, session-related data is stored in RAM. The only time an ephemeral session writes data to disk is when you tell it to write the contents of a URL to a file.

In other words it’s an Incognito tab in your Network library. Where it won’t use or persist any cache for the request.

Interesting Point to know 🧐:

  • Doesn’t write cached data to disk
  • The size of the cache is limited by available RAM
  • This limitation means that previously fetched resources are less likely to be in the cache (and are guaranteed to not be there if the user quits and relaunches your app)
  • May lead to a decrease in perceived performance
  • Data is purged when — app invalidates the session
  • Data is purged when — app is terminated
  • Data is purged when — when the system experiences memory pressure
  • Data is not purged automatically when your app is suspended

Use Cases 👨🏻‍⚖️:

  • It is always useful to have ephemeral session configuration objects available in your network layer so that you inject it as per requirement. This helps in debugging network call while developing or debugging.
  • It is also a good choice when you are writing network related test cases as we want to run each test in isolation so that there won’t be any side effect from other test cases. Such as mocking server response with URLProtocol.
  • It is also a good choice while implementing security related implementation such as SSL Pinning in your app.
  • To enable more security in your Payment oriented API’s where we do not want any leakage of data.

Thank you for reading 🧑🏻‍💻

Be sure to clap 👏🏼 and follow 🚶🏻‍♂️

Questions❓Feedback 📫 — please drop you comments 💭

If you like this article, feel free to share it with your friends 📨

Follow me: Linkedin | X(Twitter) | Github 🤝🏼

--

--

No responses yet