{"id":13533225,"url":"https://github.com/lxsmnsyc/solid-cache","last_synced_at":"2025-10-29T03:15:05.903Z","repository":{"id":43165757,"uuid":"509902748","full_name":"lxsmnsyc/solid-cache","owner":"lxsmnsyc","description":"Resource caching in SolidJS","archived":false,"fork":false,"pushed_at":"2025-03-14T02:59:13.000Z","size":544,"stargazers_count":36,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-18T07:21:03.884Z","etag":null,"topics":["cache","fetch","solid-js","suspense"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lxsmnsyc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"lxsmnsyc"}},"created_at":"2022-07-03T02:16:37.000Z","updated_at":"2025-10-01T09:20:32.000Z","dependencies_parsed_at":"2025-04-19T12:51:54.575Z","dependency_job_id":null,"html_url":"https://github.com/lxsmnsyc/solid-cache","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"c4aac7d2e450699800e5d47b0292c93a5321ebab"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/lxsmnsyc/solid-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2Fsolid-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2Fsolid-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2Fsolid-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2Fsolid-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lxsmnsyc","download_url":"https://codeload.github.com/lxsmnsyc/solid-cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxsmnsyc%2Fsolid-cache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281485693,"owners_count":26509764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-28T02:00:06.022Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","fetch","solid-js","suspense"],"created_at":"2024-08-01T07:01:17.814Z","updated_at":"2025-10-29T03:15:05.861Z","avatar_url":"https://github.com/lxsmnsyc.png","language":"TypeScript","readme":"# solid-cache\n\n\u003e Cache boundaries and resource caching in SolidJS\n\n[![NPM](https://img.shields.io/npm/v/solid-cache.svg)](https://www.npmjs.com/package/solid-cache) [![JavaScript Style Guide](https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript)[![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?style=flat-square\u0026logo=codesandbox)](https://codesandbox.io/s/github/LXSMNSYC/solid-cache/tree/main/examples/demo)\n\n## Install\n\n```bash\nnpm i solid-cache\n```\n\n```bash\nyarn add solid-cache\n```\n\n```bash\npnpm add solid-cache\n```\n\n## Usage\n\n### `\u003cCacheBoundary\u003e`\n\n`\u003cCacheBoundary\u003e` creates a contextual cache for all the cached resources to read/write resource results.\n\n```jsx\nimport { CacheBoundary } from 'solid-cache';\n\nexport default function App() {\n  return (\n    \u003cCacheBoundary\u003e\n      \u003cMain /\u003e\n    \u003c/CacheBoundary\u003e\n  );\n}\n```\n\nIt's ideal to add a `\u003cCacheBoundary\u003e` at the root of your application, but you can also do it granularly such that different parts of the application don't have to share the same cache.\n\n```jsx\n\u003c\u003e\n  \u003cCacheBoundary\u003e\n    \u003cNavigation /\u003e\n  \u003c/CacheBoundary\u003e\n  \u003cCacheBoundary\u003e\n    \u003cPageContent /\u003e\n  \u003c/CacheBoundary\u003e\n\u003c/\u003e\n```\n\n### `createCachedResource`\n\nA primitive similar to `createResource`, except `createCachedResource` works differently.\n\nFor `createCacheResource` to be \"cached\", it requires a `\u003cCacheBoundary\u003e` as an ancestor component, and it needs a \"key\" so it knows where to access or share its cached data.\n\n`createCachedResource` also returns `data` and `isFetching`: `data` is a `Resource` while `isFetching` is a reactive boolean signal.\n\n```jsx\nimport { createCachedResource } from 'solid-cache';\n\nfunction Profile() {\n  const { data, isFetching } = createCachedResource({\n    key: '/profile',\n    get: () =\u003e getUserProfile(),\n  });\n\n  return (\n    \u003cdiv\n      style={{\n        opacity: isFetching() ? 0.5 : 1,\n      }}\n    \u003e\n      \u003cSuspense fallback={\u003cProfileSkeleton /\u003e}\u003e\n        \u003cProfileDetails data={data()?.details} /\u003e\n        \u003cProfileTimeline data={data()?.posts} /\u003e\n      \u003c/Suspense\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n`createCachedResource` can also accept a `source` like `createResource` however it won't refetch if the `key` remains unchanged.\n\n```jsx\nconst { data, isFetching } = createCachedResource({\n  source: () =\u003e id(),\n  key: (currentId) =\u003e `/user/${currentId}`,\n  get: (currentID) =\u003e getUser(currentId),\n});\n```\n\nIf there are multiple `createCachedResource` instances that share the same key, only one is going to fetch and the rest will re-use the same cached value as the fetching instance.\n\n### `useCacheBoundaryRefresh`\n\n`useCacheBoundaryRefresh` returns a function that makes all `createCachedResource` instances to simultaneously refresh in the same `\u003cCacheBoundary\u003e`.\n\n```js\nfunction RefreshUser() {\n  const refresh = useCacheBoundaryRefresh();\n\n  return \u003cRefreshButton onClick={() =\u003e refresh()} /\u003e\n}\n```\n\nHowever, if you want to \"refresh in the background\" while keeping the old data, you can call `refresh(true)` instead, this way, the UI doesn't need to show a loading UI.\n\n### `fetch`\n\nA wrapper for `createCachedResource` and the native `fetch` API.\n\n```jsx\nimport { fetch } from 'solid-cache';\n\nfunction DogImage() {\n  const { data, isFetching } = fetch('https://dog.ceo/api/breed/shiba/images/random').json();\n\n  return (\n    \u003cSuspense\u003e\n      \u003cimg\n        src={data()?.message}\n        style={{ opacity: isFetching() ? 0.5 : 1 }}\n      /\u003e\n    \u003c/Suspense\u003e\n  );\n}\n```\n\n## Sponsors\n\n![Sponsors](https://github.com/lxsmnsyc/sponsors/blob/main/sponsors.svg?raw=true)\n\n## License\n\nMIT © [lxsmnsyc](https://github.com/lxsmnsyc)\n","funding_links":["https://github.com/sponsors/lxsmnsyc"],"categories":["📦 Components \u0026 Libraries"],"sub_categories":["Storage"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxsmnsyc%2Fsolid-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flxsmnsyc%2Fsolid-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxsmnsyc%2Fsolid-cache/lists"}