gpt4 book ai didi

How to keep the plugin's cached data when vscode plugin is updated?(vscode插件更新时,如何保持插件的缓存数据?)

转载 作者:bug小助手 更新时间:2023-10-22 13:51:00 32 4
gpt4 key购买 nike



I recently developed a vscode plugin, since in the code I would cache some data to local disk, when the plugin was updated, I found that the previously cached data were gone.

我最近开发了一个vscode插件,因为在代码中我会将一些数据缓存到本地磁盘,当插件更新时,我发现以前缓存的数据不见了。


After checking, since the data cached by the plugin is stored in the plugin's installation directory, when the plugin is updated, the old plugin will be deleted, so its corresponding data will also be deleted.

经过检查,由于插件缓存的数据存储在插件的安装目录中,当插件更新时,旧插件会被删除,因此其相应的数据也会被删除。


Is there any way to realize that the cached data will not be deleted when the plugin is updated?

有没有什么方法可以实现插件更新时缓存的数据不会被删除?


My current solution, when the vscode plugin is launched, is to find the previous version of the plugin directory by getting the installation directory of the plugin (I've found that when the plugin is updated, the old plugin isn't deleted right away, but rather the next time vscode is launched), and to copy the cached data files from within the previous version of the plugin

我目前的解决方案是,当vscode插件启动时,通过获取插件的安装目录来找到插件目录的前一个版本(我发现,当插件更新时,旧插件不会立即删除,而是在下一次启动vscode时删除),并从插件的前一版本中复制缓存的数据文件


更多回答
优秀答案推荐

You could use the ExtensionContext.globalStoragePath variable, and store your cache there. More info here https://code.visualstudio.com/updates/v1_31#_global-storage-path.

您可以使用ExtensionContext.globalStoragePath变量,并将缓存存储在那里。更多信息请点击此处https://code.visualstudio.com/updates/v1_31#_global-存储路径。


Hope this helps

希望这能有所帮助


更多回答

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com