-
Notifications
You must be signed in to change notification settings - Fork 43
feat(cache): add backward compatibility for pako 1.x to 2.x migration #1383
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
base: master
Are you sure you want to change the base?
Changes from all commits
98c0abc
fee86d3
495b1f9
c72ba89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,6 +123,8 @@ | |
| "sinon": "^21.0.0", | ||
| "supertest": "^ 7.1.3", | ||
| "testcontainers": "^11.2.1", | ||
| "typescript": "5.8.3" | ||
| "typescript": "5.8.3", | ||
| "pako": "^2.1.0", | ||
| "pako-1": "npm:pako@^1.0.8" | ||
|
Comment on lines
+127
to
+128
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: sort alphabetically. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,7 +90,23 @@ class RedisCache { | |
|
|
||
| let result | ||
| try { | ||
| const buffer = Buffer.from(typeof cacheItem === 'string' ? cacheItem : cacheItem.toString(), 'base64') | ||
| // Ensure cacheItem is treated as a string | ||
| const dataString = typeof cacheItem === 'string' ? cacheItem : String(cacheItem) | ||
|
|
||
| // Detect format: base64 (new) vs binary string (old) | ||
| // Base64 only contains A-Z, a-z, 0-9, +, /, and optional = padding | ||
| const isBase64 = /^[A-Za-z0-9+/]+=*$/.test(dataString) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of our cached values are objects and this works well for those cases. When a number is cached (e.g. statusService.requestCount), isBase64 becomes false positive. The number of such cases is small. |
||
|
|
||
| let buffer | ||
| if (isBase64) { | ||
| // NEW format: base64 encoded (written by Pako 2.1.0) | ||
| buffer = Buffer.from(dataString, 'base64') | ||
| } else { | ||
| // OLD format: binary string (written by Pako 1.0.8 with { to: 'string' }) | ||
| // Use 'binary' encoding to preserve byte values | ||
| buffer = Buffer.from(dataString, 'binary') | ||
| } | ||
|
|
||
| result = pako.inflate(buffer, { to: 'string' }) | ||
| } catch (err) { | ||
| // Disregard decompression errors gracefully as cache may be stored in an older format, missing or expired. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ function serviceFactory(options) { | |
| const realOptions = options || { | ||
| service: config.get('CACHING_REDIS_SERVICE'), | ||
| apiKey: config.get('CACHING_REDIS_API_KEY'), | ||
| port: Number(config.get('CACHING_REDIS_PORT')) || 6380 | ||
| port: Number(config.get('CACHING_REDIS_PORT')) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was the removal of |
||
| } | ||
| return redis(realOptions) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate? pako is already listed in dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it's pako v1 and v2 for backwards compat.