taplo icon indicating copy to clipboard operation
taplo copied to clipboard

local schema files are cached

Open Profpatsch opened this issue 3 years ago • 6 comments

I have a file which refers to a schema with "$schema" = "./foo.schema.json".

When I change the schema in my editor (even better toml v0.19.0), it looks like it does still try to access the old schema.

Grepping for the file name, I can find a json file at ~/.config/Code/User/globalStorage/tamasfe.even-better-toml/8f9a471d6f0705fecb69c4dcfefd8cf189a79c8c that seems to be a cache for the schema?

Maybe it’s just me, but file-system local schemas don’t really have to be cached in my opinion, it’s weird to interact with.

Profpatsch avatar Nov 03 '22 08:11 Profpatsch

Maybe content-hash the file so that you only have to re-parse and reload the schema when the schema’s content actually changes (but don’t forget to include hashes of all dependencies).

Profpatsch avatar Nov 03 '22 08:11 Profpatsch

I work within WSL so my cache is located under ~/.vscode-server/data/User/globalStorage/tamasfe.even-better-toml/

It's cached for 10 minutes according to source, but I agree on detecting expiry with some kind of hash so any WSL reload will read changes, if any.

lasantosr avatar Nov 24 '22 16:11 lasantosr

I observe the same behavior. When iterating on the local schema, I set up a periodic removal of the cache. Removal of the cache using https://github.com/microsoft/vscode/issues/138524 is also helpful.

AlexTereshenkov avatar Dec 28 '22 19:12 AlexTereshenkov

I just came across the same issue. I don't have a deep understanding of LSP stuff, but would there be any reason not to register Taplo to receive DidChangeTextDocument for .json files? Then it could cache-bust whenever a schema document is modified.

rossng avatar Jan 12 '23 14:01 rossng

Yeah caching is definitely an issue for developing schemas locally!

uncenter avatar Oct 19 '23 11:10 uncenter

Encountered the same issue. As far as I’m concerned, it’s even worse. Taplo does roughly this when loading the scheme:

schema = tryGetFromMemory else tryGetFromDiskCache else loadFromUrl
saveInMemory(schema)
saveOnDisk(schema)

So if I delete the disk cache, it rewrites it again from memory. I have to delete the disk cache and reload the extension before it tries to access the scheme again!

Also, on mac you will find the cache at ~/Library/Application\ Support/Code/User/globalStorage/tamasfe.even-better-toml

  1. Having a disk cache for disk files does not really make sense for schema already stored locally on disk
  2. To prevent writing stale data to the disk cache, only the fetch_external function should ever write directly to cache. (Just like the cache.load function writes to the memory cache after a disk cache read)

ggris-IL avatar Aug 21 '24 09:08 ggris-IL