Resource cache
Sometimes, a plugin will want to load data from an open-ended number of resources. A motivating example is our own use of sublime-syntax and tmLanguage files in sublime_lib.syntax. Another example is the in-development SublimeTemplate package, which looks for and parses sublime-template files. A more nebulous example might be JS Custom, when I find a graceful way to handle user-provided syntax extensions.
Loading and processing all of these files could be a performance risk. The obvious solution is caching.
An eager approach using listeners might be a bit complicated. A lazier approach would be to check file modification times when a list is requested. This should probably work well enough, unless there are OS-specific issues I'm not aware of.
A cache would be initialized with:
- A pattern like
*.sublime-template, or maybe a list of patterns. - (optional) A filtering function operating on resource paths.
- A transformation, such as a parsing function.
The cache would keep a map from resource paths to:
- The actual OS file path (which might end at a
sublime-package). - That path's last modification time.
- The transformed data.
When the user requests a list of items, the cache would call sublime.find_resources, check the locations and modification times of those files, refresh any that have moved or been modified; then, return the list.
Thoughts? If the general idea seems reasonable, I'll write up a PR.
Loading and processing all of these files could be a performance risk.
I say we should only implement caching if we notice this as being a bottleneck. Anything before that is premature optimization that might not be necessary and introduces additional complexity for no benefit.