@@ -11,6 +11,8 @@ import (
1111 "github.com/aws-cloudformation/rain/internal/config"
1212)
1313
14+ var contentCache map [string ]* ModuleContent
15+
1416type 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}
0 commit comments