improve caching of images

First, we used two caches. Turns out that lru_cache wasn't needed, the
dict works perfectly fine on it's own.

Second, we now also cache local images, so that we don't have to read
them off the filesystem and convert them to base64 on every keystroke

Maybe there should be a maximum size on that cache dict, but I doubt
anyone would actually run into any trouble this cache taking too much
ram.
This commit is contained in:
Mathieu PATUREL
2019-11-16 10:07:15 +11:00
parent 2785df74ce
commit 192f61bf0c
3 changed files with 26 additions and 21 deletions

View File

@ -26,8 +26,8 @@ resources = {}
def plugin_loaded():
resources["base64_loading_image"] = get_resource("loading.base64")
resources["base64_404_image"] = get_resource("404.base64")
resources["base64_loading_image"] = get_resource("loading.base64")
resources["stylesheet"] = get_resource("stylesheet.css")
@ -222,7 +222,7 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
basepath = os.path.dirname(markdown_view.file_name())
html = markdown2html(
markdown, basepath, partial(self._update_preview, markdown_view), resources
markdown, basepath, partial(self._update_preview, markdown_view), resources,
)
self.phantom_sets[markdown_view.id()].update(