{
  "schemaVersion": 1,
  "citationId": "ecn:v4/caching/caching-effects@bf46254#once",
  "citeUrl": "/cite/6157b9be7a322f77.json",
  "digest": "6157b9be7a322f77",
  "slug": "v4/caching/caching-effects",
  "version": "v4",
  "title": "缓存 Effect",
  "anchor": "once",
  "headingPath": [
    "once"
  ],
  "pageUrl": "/docs/v4/caching/caching-effects/",
  "deepLink": "/docs/v4/caching/caching-effects/#once",
  "officialUrl": "https://effect.website/docs/v4/caching/caching-effects",
  "upstreamPath": "v4/caching/caching-effects.mdx",
  "upstreamCommit": "bf4625446a02894046b6937a317dde2cde115fe7",
  "upstreamRawUrl": "https://raw.githubusercontent.com/Effect-TS/website/bf4625446a02894046b6937a317dde2cde115fe7/apps/web/src/content/docs/v4/caching/caching-effects.mdx",
  "status": "published",
  "stale": false,
  "contentHash": "a3e8edaa5adee8cc",
  "chunkText": "确保一个 Effect 只执行一次，即使它被多次调用也是如此。\n\n示例（Effect 的单次执行）\n\nconst program = Effect.gen(function () {\n const task1 = Console.log(\"task1\")\n\n // Repeats task1 three times\n yield Effect.repeat(task1, { times: 2 })\n\n // Ensures task2 is executed only once\n const task2 = yield Effect.cached(Console.log(\"task2\"))\n\n // Attempts to repeat task2, but it will only execute once\n yield Effect.repeat(task2, { times: 2 })\n})\n\nconst result = await Effect.runPromise(program)\n/\nOutput:\ntask1\ntask1\ntask1\ntask2\n/\nresult …",
  "generatedAt": "2026-09-18T14:48:33.525Z"
}
