Repository navigation
Add @pegma/cache-elasticache (Cache Core Phase 4) #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2026 RetireGolden, LLC | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # `@pegma/cache-elasticache` | ||
|
|
||
| Amazon ElastiCache adapter for [`@pegma/cache-core`](https://github.com/pegma-dev/cache-core). | ||
| A thin composition of [`@pegma/cache-redis`](https://github.com/pegma-dev/cache-core/tree/main/packages/cache-redis): | ||
| ElastiCache speaks Redis, so this package does not invent a second store. | ||
| Intended future hosts: RetireGolden.org and Exsimplify. | ||
|
|
||
| > [!IMPORTANT] | ||
| > Pegma is in early `0.x` development. This package's public API is unstable. | ||
|
|
||
| ```ts | ||
| import { createControllableClock, jsonCodec } from "@pegma/cache-core"; | ||
| import { createElastiCacheCacheStore } from "@pegma/cache-elasticache"; | ||
| import { Redis } from "ioredis"; | ||
|
|
||
| const clock = createControllableClock("2026-08-15T16:00:00.000Z"); | ||
| const cache = createElastiCacheCacheStore({ | ||
| clock, | ||
| // Primary endpoint. A cluster-mode configuration endpoint needs Redis.Cluster. | ||
| redis: new Redis({ | ||
| host: process.env.ELASTICACHE_HOST ?? "127.0.0.1", | ||
| port: Number(process.env.ELASTICACHE_PORT ?? "6379"), | ||
| password: process.env.ELASTICACHE_AUTH_TOKEN, | ||
| tls: {}, | ||
| }), | ||
| }); | ||
| const codec = jsonCodec<string>(); | ||
|
|
||
| const result = await cache.getOrCompute( | ||
| { namespace: "sessions", key: "abc", hashTag: "user-1" }, | ||
| { | ||
| codec, | ||
| ttl: { absoluteMs: 60_000 }, | ||
| fallback: "fail-open", | ||
| compute: () => loadSession(), | ||
| }, | ||
| ); | ||
| ``` | ||
|
|
||
| Hosts depend on `CacheStore`. Construct the Redis client at the composition | ||
| root — typically TLS to the primary endpoint, with the ElastiCache AUTH | ||
| token as the password — and hand it to this adapter. A cluster-mode | ||
| configuration endpoint is not a standalone host: inject `Redis.Cluster` (or | ||
| another cluster-aware client) so slot redirects are handled there. | ||
| Application code does not import `ioredis` or an AWS data-plane SDK. | ||
|
|
||
| There is no ElastiCache data-plane Redis SDK to wrap. This factory forwards | ||
| to `createRedisCacheStore`, so TTL, sliding refresh, and XFetch still read | ||
| the injected Spine `Clock`, tag invalidation still uses a sidecar index, and | ||
| hash tags stay formatting. `formatCacheKey` embeds `{tag}` as the first | ||
| brace pair on the wire so Redis Cluster (and ElastiCache cluster mode) | ||
| colocates those keys. The port still refuses implicit cross-partition | ||
| multi-key operations. | ||
|
|
||
| This adapter passes `@pegma/cache-conformance` against a real Redis. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "name": "@pegma/cache-elasticache", | ||
| "version": "0.1.0", | ||
| "description": "Amazon ElastiCache adapter for @pegma/cache-core.", | ||
| "license": "MIT", | ||
| "type": "module", | ||
| "sideEffects": false, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "files": [ | ||
| "dist/**/*.d.ts", | ||
| "dist/**/*.d.ts.map", | ||
| "dist/**/*.js", | ||
| "dist/**/*.js.map" | ||
| ], | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.js" | ||
| } | ||
| }, | ||
| "engines": { | ||
| "node": ">=22" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/pegma-dev/cache-core.git", | ||
| "directory": "packages/cache-elasticache" | ||
| }, | ||
| "dependencies": { | ||
| "@pegma/cache-core": "0.1.0", | ||
| "@pegma/cache-redis": "0.1.0", | ||
| "@pegma/spine": "0.1.2" | ||
| }, | ||
| "devDependencies": { | ||
| "@pegma/cache-conformance": "0.1.0", | ||
| "ioredis": "^5.8.2" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsc -p tsconfig.json", | ||
| "check": "tsc -p tsconfig.json --noEmit", | ||
| "prepack": "pnpm run build" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.