From f0ed99af72070eac9498f0e218e67888f38104ee Mon Sep 17 00:00:00 2001 From: Zhang Minghan Date: Wed, 31 May 2023 18:26:00 +0800 Subject: [PATCH] update cache --- README.md | 28 +++++++++++++++++++--------- docs/en.md | 26 ++++++++++++++++++-------- package.json | 1 + src/option.ts | 2 +- src/plugin.ts | 2 +- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 4ed869b..a6746a0 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ ## 简介 Turbowarp ClipX 是一个高效开发部署turbowarp扩展的插件, 提供: - ✨ **更好的接口风格** 使用类和装饰器来定义扩展,更简洁和优雅 +- ⚡ **便捷的缓存功能** 提供缓存功能, 优化性能 (可在接口中自定义) - 🔨 **更好的开发环境** 自动补全Turbowarp类型 - 📦 **webpack 压缩** 缩小打包JS文件体积, 提高加载速度和性能 - 🎃 **注册异常检测** 注册扩展时检查异常情况并拦截汇报 @@ -18,20 +19,24 @@ Turbowarp ClipX 是一个高效开发部署turbowarp扩展的插件, 提供: - 🎉 **Action 自动打包** 使用action实现自动打包并加入release中, 方便在线获取 ## 开发 +入口 **/src/index.ts** (**javascript**同理) 1. 初始化安装依赖 (**yarn** **pnpm**同理, 推荐**pnpm**) - ```commandline + ```shell npm install ``` -2. 入口编写扩展程序 **/src/index.ts** (**javascript**同理) +2. dev + ```shell + npm run dev + ``` 3. eslint 修复 - ```commandline + ```shell npm run lint ``` -4. 打包生成 - ```commandline +4. 打包 + > webpack 打包生成的js文件位于 **dist/extension.js** + ```shell npm run build ``` -webpack打包生成的js文件位于**dist/extension.js** ## 接口 @@ -46,8 +51,11 @@ webpack打包生成的js文件位于**dist/extension.js** - `Scratch.BlockType.REPORTER` 圆形的带返回值的积木 - `Scratch.BlockType.BOOLEAN` 六边形的返回布尔值的积木 - `Scratch.BlockType.COMMAND` 一个键积木 - - `bind` 接受一个**function**, 允许异步执行返回Promise - - `text` 是一个字符串,用于定义积木在编辑器中的名称 格式为 **[参数:类型]** + - ✨ `bind` 接受一个**function**, 允许异步执行返回Promise + - ✨ `cache` 缓存 + - `enable` 是否开启缓存 + - `expiration` 缓存时间, 单位秒, 如果为**0**则永不过期 + - ✨ `text` 是一个字符串,用于定义积木在编辑器中的名称 格式为 **[参数:类型]** - `参数` 定义积木接受的参数的对象, 可能将在`default`和`menu`字段中引用 - `类型`定义要创建的输入形状 *(不区分大小写)* - `STRING` 字符串类型 @@ -60,7 +68,9 @@ webpack打包生成的js文件位于**dist/extension.js** - `default` 是参数的初始值, 接受一个字典, 键对应`参数`, 值对应参数的`默认值` - `menu` 如果有参数需选择多个给定的值, 则可加入至此参数, 接受一个字典, 键对应`参数`, 值对应多个给定的值的列表类型, 将生成下拉菜单 - `disableMonitor` 是否积木强制删除复选框来创建监视器, 适用类型为**REPORTER** *(带返回值的积木)*, 如果为真, 则删除变量左处的复选框 -5. `docsURI`对应文档链接 +5. `docsURI` 对应文档链接 +6. ✨ `debug` 是否开启控制台调试 (默认关闭, 即此插件本身不会有任何输出) +7. ✨ `uptime` 定期缓存清理时间间隔, 单位秒, 默认为**60**秒 没太看懂? 下面展示一个示例 ```typescript diff --git a/docs/en.md b/docs/en.md index 32d24c5..fc0dd07 100644 --- a/docs/en.md +++ b/docs/en.md @@ -9,6 +9,7 @@ ## Introduction - ✨ **Better interface style** Use classes and decorators to define extensions, more concise and elegant +- ⚡ **Convenient caching functionality** Provides caching functionality to optimize performance (customizable in the interface) - 🔨 **Better development environment** Auto-completion of Turbowarp types - 📦 **webpack compression** Reduces the size of packaged JS files, improves loading speed and performance - 🎃 **Registration Exception Detection** Check for exceptions and intercept reports when registering extensions @@ -17,20 +18,24 @@ - 🎉 **Action Auto Build** Use action to implement auto-package and add to release, easy to get online ## Development +entrypoint **/src/index.ts** (**javascript** same) 1. Initial installation of dependencies (**yarn** **pnpm** same, **pnpm** recommended) - ```commandline + ```shell npm install ``` -2. import write extensions **/src/index.ts** (**javascript** same) +2. dev + ```shell + npm run dev + ``` 3. eslint fix - ```commandline + ```shell npm run lint ``` -4. package generation - ```commandline +4. build + > The js file generated by webpack packaging is located in **dist/extension.js** + ```shell npm run build ``` -The js file generated by **webpack** packaging is located in **dist/extension.js** ## Interface @@ -45,8 +50,11 @@ The js file generated by **webpack** packaging is located in **dist/extension.js - `Scratch.BlockType.REPORTER` Round block with return value - `Scratch.BlockType.BOOLEAN` A hexagonal block that returns a boolean value - `Scratch.BlockType.COMMAND` A key block - - `bind` accepts a **function**, allowing asynchronous execution to return a Promise - - `text` is a string that defines the name of the block in the editor in the format **[parameter:type]** + - ✨ `bind` accepts a **function**, allowing asynchronous execution to return a Promise + - ✨ `cache` Cache + - `enable` whether to turn on caching + - `expiration` cache time, in seconds, if **0** then never expires + - ✨ `text` is a string that defines the name of the block in the editor in the format **[parameter:type]** - `parameters` defines the objects that the building block accepts as parameters, possibly referenced in the `default` and `menu` fields - `TYPE` defines the input shape to be created *(case-insensitive)* - `STRING` string type @@ -60,6 +68,8 @@ The js file generated by **webpack** packaging is located in **dist/extension.js - `menu` can be added to this parameter if there are parameters to select more than one given value, accepts a dictionary, key corresponds to `parameter`, value corresponds to the list type of more than one given value, will generate a drop-down menu - `disableMonitor` if or not the block forces to remove the checkbox to create a monitor, applicable type is **REPORTER** *(block with return value)*, if true, then remove the checkbox to the left of the variable 5. `docsURI` corresponds to document link +6. ✨ `debug` whether to open the console debugging (default is false, that is, the plugin itself will not have any output) +7. ✨ `uptime` periodic cache cleaning interval, in seconds, default is **60** seconds Don't quite get it? Here's an example ```typescript diff --git a/package.json b/package.json index cba2ce2..e136db3 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "📦 TurboWarp development-env extension plugin", "main": "index.ts", "scripts": { + "dev": "webpack --watch", "build": "webpack", "lint": "eslint src/** --fix" }, diff --git a/src/option.ts b/src/option.ts index 4d2e2cd..a27cb9f 100644 --- a/src/option.ts +++ b/src/option.ts @@ -10,7 +10,7 @@ export default interface Option { docsURI?: string // Should be a data: URI blocks: Block[] debug?: boolean // Defaults to false if not specified. - secs?: number // Timing of cache cleaning. Defaults to 60(secs) if not specified. + uptime?: number // Timing of cache cleaning. Defaults to 60(secs) if not specified. } const $ = Scratch.BlockType diff --git a/src/plugin.ts b/src/plugin.ts index e64b785..42e7f36 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -9,7 +9,7 @@ export default class Extension { public constructor(option: Option) { this.option = option; - this.cache = new Cache(option.secs || 60, option.debug || false); + this.cache = new Cache(option.uptime, option.debug); this.blocks = []; this.menus = {};