Skip to content

Commit

Permalink
Merge pull request #7 from opentorc/develop
Browse files Browse the repository at this point in the history
Add Caching
  • Loading branch information
ritesh-cs authored Dec 12, 2022
2 parents 122e25a + 690500b commit 7cec38c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions codealike.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"projectId":"0bf825e0-7a14-11ed-9fab-c79574c4e560","projectName":"config-wrapper"}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentorc/config-wrapper",
"version": "1.2.2",
"version": "1.2.3",
"description": "config management wrapper",
"main": "./src/index.js",
"bin": {
Expand Down
11 changes: 10 additions & 1 deletion src/lib/awsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ let ssm

const BASE_PATH = '/torc'

const cachedParams = {}

function initializeSSM() {
if (!ssm) {
ssm = new AWS.SSM();
Expand Down Expand Up @@ -44,6 +46,12 @@ async function getParameter(env, service, paramName, isEncrypted) {
async function getParametersByService(env, service, isEncrypted) {
const Path = constructParamPath(env, service)
console.log(`Getting parameters from ${Path}`)

if (cachedParams[Path]) {
console.log('Found parameters in cache. Returning...')
return cachedParams[Path]
}

var config = {
Path,
Recursive: true,
Expand All @@ -63,11 +71,12 @@ async function getParametersByService(env, service, isEncrypted) {
convertedParams[param.name] = param
}

params = await ssm.getParametersByPath(config).promise()
nextToken = params.NextToken
config.NextToken = nextToken
} while (nextToken)

cachedParams[Path] = convertedParams

return convertedParams
}

Expand Down

0 comments on commit 7cec38c

Please sign in to comment.