# If I want a plugin to cache a remotely-fetched file for later quick access, how might I do that?

**URL:** https://platform.jetbrains.com/t/if-i-want-a-plugin-to-cache-a-remotely-fetched-file-for-later-quick-access-how-might-i-do-that/1462
**Category:** IntelliJ Platform
**Tags:** api
**Created:** [April 22, 2025, 10:19pm UTC](https://platform.jetbrains.com/t/if-i-want-a-plugin-to-cache-a-remotely-fetched-file-for-later-quick-access-how-might-i-do-that/1462 "2025-04-22T22:19:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kshetline.1](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/kshetline.1/32/1056_2.png) [@kshetline.1](https://platform.jetbrains.com/u/kshetline.1)
#### Post date: [April 22, 2025, 10:19pm UTC](https://platform.jetbrains.com/t/if-i-want-a-plugin-to-cache-a-remotely-fetched-file-for-later-quick-access-how-might-i-do-that/1462/1 "2025-04-22T22:19:37Z")

</div>

Is their an existing API for file caching, one that a plugin could use to stash a remotely-acquired resource for quick access?

Something automatically maintained by the IDEA environment, so that a plugin doesn’t have to worry about choosing the directory path for where cached files should be stored?

---

<div class="post-metadata">

### Author: ![insyncwithfoo](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/insyncwithfoo/32/158_2.png) [@insyncwithfoo](https://platform.jetbrains.com/u/insyncwithfoo)
#### Post date: [April 22, 2025, 11:12pm UTC](https://platform.jetbrains.com/t/if-i-want-a-plugin-to-cache-a-remotely-fetched-file-for-later-quick-access-how-might-i-do-that/1462/2 "2025-04-22T23:12:54Z")

</div>

There’s [`VirtualFileManager.findFileByUrl()`](https://github.com/JetBrains/intellij-community/blob/4898fafd5c3283c5e4498cb5919d299ef90a7ce7/platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFileManagerImpl.java#L361-L364), which eventually delegates to [`HttpFileSystemBase.findFileByPath()`](https://github.com/JetBrains/intellij-community/blob/4898fafd5c3283c5e4498cb5919d299ef90a7ce7/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/HttpFileSystemBase.java#L23-L30).

(Assuming by “remote”, you mean “over the web”.)

---

<div class="post-metadata">

### Author: ![kshetline.1](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/kshetline.1/32/1056_2.png) [@kshetline.1](https://platform.jetbrains.com/u/kshetline.1)
#### Post date: [April 23, 2025, 1:51am UTC](https://platform.jetbrains.com/t/if-i-want-a-plugin-to-cache-a-remotely-fetched-file-for-later-quick-access-how-might-i-do-that/1462/3 "2025-04-23T01:51:04Z")

</div>

I can’t seem to get this to work

```kotlin
  latestJS = VfsUtil.loadText(VirtualFileManager.getInstance()
    .findFileByUrl("https://unpkg.com/@highlightjs/cdn-assets/highlight.min.js")!!)

```

I needed to add `getInstance()`, by the way, but that only made the code compile, not work correctly.

A simple:

```auto
 URL("https://unpkg.com/@highlightjs/cdn-assets/highlight.min.js").readText()

```

…does work, but I don’t know if that provides any caching or not.

```auto
VirtualFileManager.getInstance()
    .findFileByUrl("https://unpkg.com/@highlightjs/cdn-assets/highlight.min.js")

```

…by itself returns a non-null result, but the debugger says the local file is null, and `VfsUtil.loadText` fails with an NPE.

---

<div class="post-metadata">

### Author: ![insyncwithfoo](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/insyncwithfoo/32/158_2.png) [@insyncwithfoo](https://platform.jetbrains.com/u/insyncwithfoo)
#### Post date: [April 23, 2025, 2:20am UTC](https://platform.jetbrains.com/t/if-i-want-a-plugin-to-cache-a-remotely-fetched-file-for-later-quick-access-how-might-i-do-that/1462/4 "2025-04-23T02:20:21Z")

</div>

> [@kshetline.1](#):
>
> I don’t know if that provides any caching or not.

IIRC the results is cached in a directory called `httpFileSystem`. I’m not sure if it’s part of the contract though. For the record, there are a couple of related bug reports on YouTrack, like [this one](https://youtrack.jetbrains.com/issue/DEXP-573764).

Highlight.js in particular is very stable (11.9.0 was released in October 2023, 11.10.0 in July 2024, 11.11.0 and 11.11.1 in December 2024), and the minified file is just over 120 KB long. You could bundle it with your plugin. `PropertiesComponent` is also a choice, though probably not recommended.

---

<div class="post-metadata">

### Author: ![kshetline.1](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/kshetline.1/32/1056_2.png) [@kshetline.1](https://platform.jetbrains.com/u/kshetline.1)
#### Post date: [April 23, 2025, 2:42am UTC](https://platform.jetbrains.com/t/if-i-want-a-plugin-to-cache-a-remotely-fetched-file-for-later-quick-access-how-might-i-do-that/1462/5 "2025-04-23T02:42:50Z")

</div>

I’ve actually done both things, bundling highlight.js and trying to pull down the latest version, using the bundled version as a fallback in case loading the latest fails (or is too slow loading).

Working with highlight.js so much lately, trying it out with many languages, has actually lead me to finding several bugs, so I expect to be trying to contribute a few fixes to that myself that I’ll want to have automatically download.

I was easily able to fix one CSS bug (not recognizing `unicode-range`, and then getting ugly highlighting only the decimal digits in the hex ranges that follow), but some parts of that code base are hard for a newcomer like me to get my head around.

At any rate, I guess I’ll stick with `URL...readText()` for now.
