{"id":18561422,"url":"https://github.com/apostrophecms/cache-redis","last_synced_at":"2025-05-15T16:34:28.894Z","repository":{"id":45329405,"uuid":"438040321","full_name":"apostrophecms/cache-redis","owner":"apostrophecms","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-13T17:27:31.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-08T10:54:55.239Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/apostrophecms.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2021-12-13T22:12:09.000Z","updated_at":"2021-12-20T20:19:41.000Z","dependencies_parsed_at":"2024-11-06T22:16:57.691Z","dependency_job_id":null,"html_url":"https://github.com/apostrophecms/cache-redis","commit_stats":{"total_commits":21,"total_committers":3,"mean_commits":7.0,"dds":"0.23809523809523814","last_synced_commit":"24f375ba16c1583f8cc1d063ff762629717326c0"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apostrophecms%2Fcache-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apostrophecms%2Fcache-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apostrophecms%2Fcache-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apostrophecms%2Fcache-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apostrophecms","download_url":"https://codeload.github.com/apostrophecms/cache-redis/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254179905,"owners_count":22027884,"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","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":[],"created_at":"2024-11-06T22:06:48.172Z","updated_at":"2025-05-15T16:34:28.871Z","avatar_url":"https://github.com/apostrophecms.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/apostrophecms/apostrophe/main/logo.svg\" alt=\"ApostropheCMS logo\" width=\"80\" height=\"80\"\u003e\n\n  \u003ch1\u003eApostrophe Redis Cache\u003c/h1\u003e\n  \u003cp\u003e\n    \u003ca aria-label=\"Apostrophe logo\" href=\"https://v3.docs.apostrophecms.org\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/MADE%20FOR%20ApostropheCMS-000000.svg?style=for-the-badge\u0026logo=Apostrophe\u0026labelColor=6516dd\"\u003e\n    \u003c/a\u003e\n    \u003ca aria-label=\"Test status\" href=\"https://github.com/apostrophecms/cache-redis/actions\"\u003e\n      \u003cimg alt=\"GitHub Workflow Status (branch)\" src=\"https://img.shields.io/github/workflow/status/apostrophecms/cache-redis/tests/main?label=Tests\u0026logo=github\u0026labelColor=000\u0026style=for-the-badge\"\u003e\n    \u003c/a\u003e\n    \u003ca aria-label=\"Join the community on Discord\" href=\"http://chat.apostrophecms.org\"\u003e\n      \u003cimg alt=\"\" src=\"https://img.shields.io/discord/517772094482677790?color=5865f2\u0026label=Join%20the%20Discord\u0026logo=discord\u0026logoColor=fff\u0026labelColor=000\u0026style=for-the-badge\u0026logoWidth=20\"\u003e\n    \u003c/a\u003e\n    \u003ca aria-label=\"License\" href=\"https://github.com/apostrophecms/cache-redis/blob/main/LICENSE.md\"\u003e\n      \u003cimg alt=\"\" src=\"https://img.shields.io/static/v1?style=for-the-badge\u0026labelColor=000000\u0026label=License\u0026message=MIT\u0026color=3DA639\"\u003e\n    \u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\nThis module enhances the core caching module, `@apostrophecms/cache`, to use [Redis](https://redis.io/) rather than MongoDB. This module does not set up the actual Redis store, but instead allows Apostrophe to access an existing Redis store through the standard Apostrophe caching API and an internal Redis client.\n\nAll normal Apostrophe cache API features are maintained in addition to the Redis-specific features described below.\n\n## Installation\n\nTo install the module, use the command line to run this command in an Apostrophe project's root directory:\n\n```\nnpm install @apostrophecms/cache-redis\n```\n\n## Usage\n\nConfigure the Redis cache module in the `app.js` file:\n\n```javascript\nrequire('apostrophe')({\n  shortName: 'my-project',\n  modules: {\n    '@apostrophecms/cache-redis': {}\n  }\n});\n```\n\n## Configuring Redis options\n\n**All options for this module should be applied to `@apostrophecms/cache` in project code.** This module simply \"improves\" that core module (updates its features). The main caching module still does all the work.\n\nConfigure the underlying Redis client by adding a configuration object on the cache module's `redis` option.\n\n```javascript\n// modules/@apostrophecms/cache/index.js\nmodule.exports = {\n  options: {\n    redis: {\n      url: 'redis://alice:foobared@awesome.redis.server:6380'\n    }\n  }\n};\n```\n\nBy default, the client will look for a Redis server running on localhost port 6379. See [all the client configuration options](https://github.com/redis/node-redis/blob/master/docs/client-configuration.md) on the Node-Redis documentation.\n\nNote that this module uses the 4.x version of Node-Redis, which changed its configuration options from earlier major versions.\n\n## Cache keys\n\nThe Apostrophe cache `get` and `set` methods take two arguments that are used for individual cache item keys:\n\n| Argument | Description |\n| -------- | ----------- |\n| `namespace` | A namespace for related data. Apostrophe core often uses the active module's name for the namespace, e.g., `@apostrophecms/oembed`. |\n| `key` | The unique cache item key within a namespace. |\n\n```javascript\nawait apos.cache.get(namespace, key)\nawait apos.cache.set(namespace, key, value)\n```\n\nExample:\n\n```javascript\nconst fetch = node\n// modules/api-connect/index.js\nmodule.exports = {\n  apiRoutes(self) {\n    return {\n      get: {\n        // GET /api/v1/api-connect/set-cache-info\n        async setCacheInfo(req) {\n          const info = await myApiClient.get({ latest: true });\n\n          // 👇 This status will be \"OK\" if successful. This is due to the Redis\n          // API, not a common Apostrophe pattern.\n          const status = await self.apos.cache.set('api-connect', 'latest', info);\n\n          return { status };\n        },\n        // GET /api/v1/api-connect/get-cache-info\n        async getCacheInfo(req) {\n          // 👇 This will return the stored information or `undefined` if not\n          // set.\n          const latest = await self.apos.cache.get('api-connect', 'latest');\n\n          return { latest };\n        }\n      }\n    };\n  }\n};\n```\n\n### Using the `prefix` for multiple sites\n\nBy default, this module applies a prefix to cache keys in the store. This prefix is the shortname of the website, which automatically separates cache items if multiple Apostrophe sites share the same Redis store.\n\nTo disable the cache key prefix, set the cache module's `prefix` option to `false`.\n\n```javascript\n// modules/@apostrophecms/cache/index.js\nmodule.exports = {\n  options: {\n    prefix: false\n  }\n};\n```\n\nTo customize the prefix, set the `prefix` option to the desired string value.\n\n```javascript\n// modules/@apostrophecms/cache/index.js\nmodule.exports = {\n  options: {\n    prefix: 'project-alpha'\n  }\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapostrophecms%2Fcache-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapostrophecms%2Fcache-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapostrophecms%2Fcache-redis/lists"}