Skip to content

Commit be66ba9

Browse files
committed
👍 Use context attribute for cache
1 parent 0805cfb commit be66ba9

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

denops_std/buffer/buffer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Denops } from "https://deno.land/x/denops_core@v3.0.2/mod.ts";
22
import * as autocmd from "../autocmd/mod.ts";
33
import * as batch from "../batch/mod.ts";
44
import * as fn from "../function/mod.ts";
5-
import * as vars from "../variable/mod.ts";
65
import { execute } from "../helper/mod.ts";
76
import * as unknownutil from "https://deno.land/x/unknownutil@v2.0.0/mod.ts";
87
import {
@@ -15,15 +14,15 @@ import {
1514
import { tryDecode } from "./fileencoding.ts";
1615
import { generateUniqueString } from "../util.ts";
1716

17+
const cacheKey = Symbol("denops_std/buffer/buffer.ts");
1818
const suffix = generateUniqueString();
1919

2020
async function ensurePrerequisites(denops: Denops): Promise<string> {
21-
if (await vars.g.get(denops, `loaded_denops_std_buffer_${suffix}`)) {
21+
if (cacheKey in denops.context) {
2222
return suffix;
2323
}
24+
denops.context[cacheKey] = true;
2425
const script = `
25-
let g:loaded_denops_std_buffer_${suffix} = 1
26-
2726
function! DenopsStdBufferReload_${suffix}(bufnr) abort
2827
if bufnr('%') is# a:bufnr
2928
edit

denops_std/helper/echo.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import type { Denops } from "https://deno.land/x/denops_core@v3.0.2/mod.ts";
2-
import * as vars from "../variable/mod.ts";
32
import { execute } from "./execute.ts";
43
import { batch } from "../batch/mod.ts";
54
import { generateUniqueString } from "../util.ts";
65

6+
const cacheKey = Symbol("denops_std/helper/echo");
77
const suffix = generateUniqueString();
88

99
async function ensurePrerequisites(denops: Denops): Promise<string> {
10-
if (await vars.g.get(denops, `loaded_denops_std_helper_echo_${suffix}`)) {
10+
if (cacheKey in denops.context) {
1111
return suffix;
1212
}
13+
denops.context[cacheKey] = true;
1314
const script = `
1415
let g:loaded_denops_std_helper_echo_${suffix} = 1
1516

denops_std/helper/input.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import {
44
assertString,
55
} from "https://deno.land/x/unknownutil@v2.0.0/mod.ts";
66
import * as fn from "../function/mod.ts";
7-
import * as vars from "../variable/mod.ts";
87
import * as anonymous from "../anonymous/mod.ts";
98
import { execute } from "./execute.ts";
109
import { generateUniqueString } from "../util.ts";
1110

11+
const cacheKey = Symbol("denops_std/helper/input");
1212
const suffix = generateUniqueString();
1313

1414
async function ensurePrerequisites(denops: Denops): Promise<string> {
15-
if (await vars.g.get(denops, `loaded_denops_std_helper_input_${suffix}`)) {
15+
if (cacheKey in denops.context) {
1616
return suffix;
1717
}
18+
denops.context[cacheKey] = true;
1819
const script = `
1920
let s:loaded_denops_std_helper_input_${suffix} = 1
2021

0 commit comments

Comments
 (0)