awslabs / diagram-as-code

Diagram-as-code for AWS architecture.
Apache License 2.0
406 stars 23 forks source link

Improve definition file caching #33

Closed ugwis closed 1 month ago

ugwis commented 2 months ago

Why

Currently, architecture icon and definition file caching is based on a hash of static values such as file names, and hash values do not change permanently, so changes to architecture icons and definition files are not reflected. File caching is implemented as internal/cache.

What

ugwis commented 1 month ago

Confirmed that the cache is automatically replaced by updating the definition file and use cache after it

$ ./awsdac examples/vpc-natgw.yaml -v
INFO[0000] input file: examples/vpc-natgw.yaml          
INFO[0000] Load DefinitionFiles section                 
INFO[0000] Fetch definition file from URL: https://raw.githubusercontent.com/awslabs/diagram-as-code/main/definitions/definition-for-aws-icons-light.yaml 
INFO[0000] [internal/cache/cache.go] FetchFile https://raw.githubusercontent.com/awslabs/diagram-as-code/main/definitions/definition-for-aws-icons-light.yaml 
INFO[0000] [internal/cache/cache.go] Found previous Etag cache. Use HTTP Etag value "d4dce883bb896a1a248e8886f8e485fc949977307e3b238601a0c90147c81fd1" 
INFO[0000] [internal/cache/cache.go] Server respond with HTTP 200 
INFO[0000] [internal/cache/cache.go] Server respond with Etag. Save Etag value "52aa0a4e488e0af8a02de5e92a4875d602ab77c1e18c80c7d10a4864a6e316ed" 
INFO[0000] Read definition file from cache file: /Users/kitayu/.cache/awsdac/850960c5c172c277f880286d0349c39c-definition-for-aws-icons-light.yaml
...
$ ./awsdac examples/vpc-natgw.yaml -v
INFO[0000] input file: examples/vpc-natgw.yaml          
INFO[0000] Load DefinitionFiles section                 
INFO[0000] Fetch definition file from URL: https://raw.githubusercontent.com/awslabs/diagram-as-code/main/definitions/definition-for-aws-icons-light.yaml 
INFO[0000] [internal/cache/cache.go] FetchFile https://raw.githubusercontent.com/awslabs/diagram-as-code/main/definitions/definition-for-aws-icons-light.yaml 
INFO[0000] [internal/cache/cache.go] Found previous Etag cache. Use HTTP Etag value "52aa0a4e488e0af8a02de5e92a4875d602ab77c1e18c80c7d10a4864a6e316ed" 
INFO[0000] [internal/cache/cache.go] Server respond with HTTP 304 
INFO[0000] [internal/cache/cache.go] Use cache based on matched HTTP Etag 
INFO[0000] Read definition file from cache file: /Users/kitayu/.cache/awsdac/850960c5c172c277f880286d0349c39c-definition-for-aws-icons-light.yaml