Skip to content

Commit 1da527c

Browse files
committed
Cache module content
1 parent 71e4151 commit 1da527c

File tree

9 files changed

+31
-15
lines changed

9 files changed

+31
-15
lines changed

cft/pkg/content.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/aws-cloudformation/rain/internal/config"
1212
)
1313

14+
var contentCache map[string]*ModuleContent
15+
1416
type ModuleContent struct {
1517
Content []byte
1618
NewRootDir string
@@ -42,7 +44,15 @@ func getModuleContent(
4244
baseUri string,
4345
uri string) (*ModuleContent, error) {
4446

45-
config.Debugf("getModuleContent root: %s, uri: %s", root, uri)
47+
config.Debugf("getModuleContent root: %s, baseUri: %s, uri: %s",
48+
root, baseUri, uri)
49+
50+
cacheKey := fmt.Sprintf("%s/%s/%s", root, baseUri, uri)
51+
52+
if cached, ok := contentCache[cacheKey]; ok {
53+
config.Debugf("getModuleContent cache hit: %s", cacheKey)
54+
return cached, nil
55+
}
4656

4757
var content []byte
4858
var err error
@@ -83,16 +93,16 @@ func getModuleContent(
8393
// getModuleContent: root=cft/pkg/tmpl/awscli-modules, baseUri=, uri=package.zip/zip-module.yaml
8494
if strings.Contains(uri, ".zip/") {
8595
isZip = true
86-
96+
8797
// Extract the zip location and path within the zip
8898
zipIndex := strings.Index(uri, ".zip/")
8999
if zipIndex > 0 {
90-
zipLocation := uri[:zipIndex+4] // Include the .zip part
91-
zipPath := uri[zipIndex+5:] // Skip the .zip/ part
92-
100+
zipLocation := uri[:zipIndex+4] // Include the .zip part
101+
zipPath := uri[zipIndex+5:] // Skip the .zip/ part
102+
93103
zipLocation = resolveZipLocation(root, zipLocation)
94104
config.Debugf("Extracting from zip: %s, path: %s", zipLocation, zipPath)
95-
105+
96106
// Use DownloadFromZip directly - it can handle S3, HTTPS, and local files
97107
content, err = DownloadFromZip(zipLocation, "", zipPath)
98108
if err != nil {
@@ -183,5 +193,11 @@ func getModuleContent(
183193
}
184194
}
185195

186-
return &ModuleContent{content, newRootDir, baseUri}, nil
196+
retval := &ModuleContent{content, newRootDir, baseUri}
197+
contentCache[cacheKey] = retval
198+
return retval, nil
199+
}
200+
201+
func init() {
202+
contentCache = make(map[string]*ModuleContent)
187203
}

test/templates/build/bucket/bucket.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Description: |
88
99
Metadata:
1010
AWSToolsMetrics:
11-
Rain: '{"Version":"v1.21.0","Experimental":true,"HasModules":true,"HasRainSection":false}'
11+
Rain: '{"Version":"v1.22.0","Experimental":true,"HasModules":true,"HasRainSection":false}'
1212

1313
Parameters:
1414
AppName:

test/templates/build/bucket/website.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Description: |
88
99
Metadata:
1010
AWSToolsMetrics:
11-
Rain: '{"Version":"v1.21.0","Experimental":true,"HasModules":true,"HasRainSection":false}'
11+
Rain: '{"Version":"v1.22.0","Experimental":true,"HasModules":true,"HasRainSection":false}'
1212

1313
Parameters:
1414
ApplicationName:

test/templates/build/ecs/cluster.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Description: |
33
44
Metadata:
55
AWSToolsMetrics:
6-
Rain: '{"Version":"v1.21.0","Experimental":true,"HasModules":true,"HasRainSection":false}'
6+
Rain: '{"Version":"v1.22.0","Experimental":true,"HasModules":true,"HasRainSection":false}'
77

88
Parameters:
99
ImageURL:

test/templates/build/eventbridge/central-logs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Description: "A central event bus rule and log group to collect CloudFormation l
44

55
Metadata:
66
AWSToolsMetrics:
7-
Rain: '{"Version":"v1.21.0","Experimental":true,"HasModules":false,"HasRainSection":false}'
7+
Rain: '{"Version":"v1.22.0","Experimental":true,"HasModules":false,"HasRainSection":false}'
88

99
Parameters:
1010
OUID:

test/templates/build/pipeline/codecommit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Description: |
88
99
Metadata:
1010
AWSToolsMetrics:
11-
Rain: '{"Version":"v1.21.0","Experimental":true,"HasModules":false,"HasRainSection":false}'
11+
Rain: '{"Version":"v1.22.0","Experimental":true,"HasModules":false,"HasRainSection":false}'
1212

1313
Parameters:
1414
ArtifactBucket:

test/templates/build/pipeline/s3.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Description: |
77
88
Metadata:
99
AWSToolsMetrics:
10-
Rain: '{"Version":"v1.21.0","Experimental":true,"HasModules":false,"HasRainSection":false}'
10+
Rain: '{"Version":"v1.22.0","Experimental":true,"HasModules":false,"HasRainSection":false}'
1111

1212
Parameters:
1313
SourceBucket:

test/templates/build/vpc/vpc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Description: "This template creates a VPC with two public and two private subnet
22

33
Metadata:
44
AWSToolsMetrics:
5-
Rain: '{"Version":"v1.21.0","Experimental":true,"HasModules":true,"HasRainSection":false}'
5+
Rain: '{"Version":"v1.22.0","Experimental":true,"HasModules":true,"HasRainSection":false}'
66

77
Resources:
88
FlowLogsRole:

test/templates/build/webapp/webapp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Description: Creates a web application with a static website using S3 and CloudF
22

33
Metadata:
44
AWSToolsMetrics:
5-
Rain: '{"Version":"v1.21.0","Experimental":true,"HasModules":false,"HasRainSection":false}'
5+
Rain: '{"Version":"v1.22.0","Experimental":true,"HasModules":false,"HasRainSection":false}'
66

77
Parameters:
88
AppName:

0 commit comments

Comments
 (0)