vapor / template-kit

📄 Easy-to-use foundation for building powerful templating languages in Swift.
MIT License
46 stars 17 forks source link

Fixes Issue #25 - Leaf template caching with non-unique keys #26

Closed foscomputerservices closed 6 years ago

foscomputerservices commented 6 years ago

Data.hashValue is not guaranteed to be unique across all Data instances. This can lead to the cache returning the wrong template.

This change uses the file name instead of Data.hashValue to key the cache. This change also means that calls to TemplateRenderer.render(template:context:file:), where the file parameter is defaulted, will no longer be cached.

joeblau commented 6 years ago

TemplateData.hashValue should be unique across all instances. The problem is that TemplateData doesn't conform to the Hashable protocol.

0xTim commented 6 years ago

@foscomputerservices conforming TemplateData to Hashable (and implementing a suitably unique tasing algorithm - if only we were on Swift 4.2) should fix this issue and is probably a better approach.

joeblau commented 6 years ago

Yeah, should be able to use a hasher and just combine into all of the properties for pre Swift 4.2.

https://developer.apple.com/documentation/swift/hashable

tanner0101 commented 6 years ago

This has been fixed in: https://github.com/vapor/template-kit/pull/31

I've also improved the render methods that accept file paths to not read files from disk if the AST is cached.