tamasfe / taplo

A TOML toolkit written in Rust
https://taplo.tamasfe.dev
MIT License
1.36k stars 114 forks source link

local schema files are cached #347

Open Profpatsch opened 1 year ago

Profpatsch commented 1 year ago

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 commented 1 year ago

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).

lasantosr commented 1 year ago

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.

AlexTereshenkov commented 1 year ago

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.

rossng commented 1 year ago

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.

uncenter commented 11 months ago

Yeah caching is definitely an issue for developing schemas locally!

ggris-IL commented 4 weeks ago

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)